alexjercan/bugnet huggingface dataset:
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdint>
#include <iostream>

using namespace std;

int32_t main() {
  uint32_t a, b, c;
  cin >> a >> b >> c;

  int32_t time = -1;
  for (uint32_t i = c; i <= (a + b) * 60; i += 60) {
    if (i % (a + b) <= a) {
      time = i;
      break;
    }
  }

  cout << time << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdint>
#include <iostream>

using namespace std;

int32_t main() {
  while (true) {
    uint32_t a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      break;

    if (60 % (a + b) == 0) {
      if (c % (a + b) <= a) {
        cout << c << endl;
      } else {
        cout << -1 << endl;
      }
    } else {
      uint32_t n = 0;
      while (((60 * n + c) % (a + b)) > a) {
        n++;
      }
      cout << n * 60 + c << endl;
    }
  }

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int a, b, c;

  cin >> a >> b >> c;

  while (c < 1000000) {
    if (0 <= c % (a + b) && c % (a + b) <= a) {
      cout << c << endl;
      return 0;
    }

    c += 60;
  }

  cout << -1 << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, c;

  cin >> a >> b >> c;

  while (c < 1000000) {
    if (0 <= c % (a + b) && c % (a + b) <= a) {
      cout << c << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int t = 0;
  for (int i = 0; i < 60; i++) {
    if (c <= t + a) {
      printf("%d\\n", c);
      return 0;
    }
    t += a + b;
    if (t > c) {
      do
        c += 60;
      while (t > c);
    }
  }
  puts("-1");
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int t = 0;
  while (true) {
    if (c <= t + a) {
      printf("%d\\n", c);
      break;
    }
    t += a + b;
    if (t > c) {
      if ((a + b) % 60 == 0) {
        puts("-1");
        break;
      }
      do
        c += 60;
      while (t > c);
    }
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int n = 0;
  while (n < 10000000) {
    if (n % 60 <= c && c <= n % 60 + a) {
      cout << n / 60 * 60 + c << endl;
      return 0;
    }
    n += a + b;
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int n = 0;
  while (n < 100000000) {
    if (n % 60 <= c && c <= n % 60 + a)
      cout << n / 60 * 60 + c << endl, n = 10000000;
    n += a + b;
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = true;
  int time = 0, cnt = 0;
  for (int i = 0; i < 1e8; i++) {
    if (time <= c && c <= time + a) {
      cout << 60 * cnt + c << endl;
      flag = false;
      break;
    }
    time += a + b;
    if (time > 60) {
      cnt++, time -= 60;
    }
  }
  if (flag)
    cout << -1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int val = 0;
  vector<int> time(1, 0);
  for (int i = 0; val < 60; i++) {
    i & 1 ? val += a : val += b;
    time.push_back(val);
  }
  val -= 60;
  vector<int> s(1, 0);
  while (val != 0) {
    s.push_back(val);
    val += val;
    val %= 60;
  }
  bool flag = true;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < time.size(); j += 2) {
      if (time[j] + s[i] <= c && c <= time[j + 1] + s[i]) {
        cout << 60 * i + c << endl;
        flag = false;
        i = s.size();
        break;
      }
    }
  }
  if (flag)
    cout << -1 << endl;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

  int a, b, c;

  cin >> a >> b >> c;

  int time = 0;
  int cnt = 100;

  while (cnt != 0) {
    time += a;
    if (time >= c)
      break;
    time += b;
    if (time >= c)
      c += 60;

    cnt--;
    if (cnt == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << c << endl;
}


Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {

  int a, b, c;
  int i;
  int t = 0;
  int total = 0;

  scanf("%d %d %d", &a, &b, &c);

  while (1) {
    for (i = 0; i < a; i++) {
      total++;

      if (total == 60 * t + c) {
        printf("%d\\n", total);
        return 0;
      }

      if (total == 60 * (t + 1)) {
        if (60 % (a + b) == 0) {
          puts("-1");
          return 0;
        } else
          t++;
      }
    }

    for (i = 0; i < b; i++) {
      total++;

      if (total == 60 * (t + 1)) {
        if (60 % (a + b) == 0) {
          puts("-1");
          return 0;
        } else
          t++;
      }
    }
  }
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int start_a = 0, start_b = a;
  while (1) {
    if (start_a <= c && c <= start_b) {
      cout << c << endl;
      break;
    }
    // int check = c - b;
    start_a += a + b;
    start_b = start_a + a;
    if (c < start_a) {
      c += 60;

      // if( c - start_b == check ){
      if (c > 100000) {
        cout << -1 << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int start_a = 0, start_b = b, end_b;
  while (1) {
    if (start_a <= c && c <= start_b) {
      cout << c << endl;
      break;
    }
    end_b = start_b + b;
    int check = c - b;
    start_a = a + b;
    start_b = start_a + b;
    end_b += end_b;
    if (c < start_a) {
      c += 60;
      if (c - start_b == check) {
        cout << -1 << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int t = 0;
  int res = 0;
  vector<vector<int>> visited(121, vector<int>(2, 0));
  visited[0][0] = 1;
  bool ok = false;

  while (1) {
    int nt = t;
    nt += a;
    res += a;
    if ((t <= c and c <= nt) or (t <= c + 60 and c + 60 <= nt)) {
      res -= (nt - c) % 60;
      ok = true;
      break;
    }
    nt %= 60;
    if (visited[nt][1] != 0)
      break;
    visited[nt][1] = 1;

    t = nt;
    nt += b;
    res += b;
    nt %= 60;
    if (visited[nt][0] != 0)
      break;
    visited[nt][0] = 1;

    t = nt;
  }

  if (not ok)
    res = -1;
  cout << res << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int t = 0;
  int res = 0;
  vector<vector<int>> visited(a + b + 1, vector<int>(2, 0));
  visited[0][0] = 1;
  bool ok = false;

  while (1) {
    int nt = t;
    nt += a;
    res += a;
    if ((t <= c and c <= nt) or (t <= c + 60 and c + 60 <= nt)) {
      res -= (nt - c) % 60;
      ok = true;
      break;
    }
    nt %= 60;
    if (visited[nt][1] != 0)
      break;
    visited[nt][1] = 1;

    t = nt;
    nt += b;
    res += b;
    nt %= 60;
    if (visited[nt][0] != 0)
      break;
    visited[nt][0] = 1;

    t = nt;
  }

  if (not ok)
    res = -1;
  cout << res << endl;

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c;
  while (cin >> a >> b >> c) {
    long long i = 0;
    while (true) {
      int sum = (a + b) * i;
      if (c >= sum % 60 && c <= sum % 60 + a) {
        sum = ceil(sum / 60) * 60 + c;
        if (sum > (a + b) * i + a) {
          sum -= 60;
        }
        cout << sum << endl;
        break;
      }
      if (i >= 1000000) {
        cout << -1 << endl;
        break;
      }
      i++;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b == 60)
    cout << -1 << endl;
  else {
    int sum = c;
    while (true) {
      if (c % (a + b) >= 0 && c % (a + b) <= a) {
        cout << sum << endl;
        break;
      }
      sum += 60;
    }
  }
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define IN cin >>
#define OUT cout <<
#define E << endl;

using namespace std;

int goal_time = 0;

int a, b, c;

int x = 0;

void input() { IN a >> b >> c; }

int main() {
  input();
  int memo = 0;

  x = 60.0 / (a + b);
  if (x == 0)
    x = 1;

  bool flag = false;
  goal_time += c;
  while (true) {
    int n = memo;
    while (true) {
      if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
        OUT goal_time E flag = true;
        break;
      }
      if ((a + b) * n > goal_time) {
        memo = n;
        break;
      }
      if (n > 5000) {
        OUT - 1 E flag = true;
        break;
      }
      n += 1;
      if (goal_time > 60) {
        if ((60 % (a + b) == 0) && c > a) {
          OUT - 1 E return 0;
        }
      }
    }
    if (flag)
      break;
    goal_time += 60;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define IN cin >>
#define OUT cout <<
#define E << endl;

using namespace std;

int goal_time = 0;

int a, b, c;

void input() { IN a >> b >> c; }

int main() {
  input();
  int memo = 0;
  if ((60 % (a + b) == 0) && c > a) {
    OUT - 1 E return 0;
  }
  bool flag = false;
  goal_time += c;
  while (true) {
    int n = memo;
    while (true) {
      if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
        OUT goal_time E flag = true;
        break;
      }
      if ((a + b) * n > goal_time) {
        memo = n;
        break;
      }
      n++;
    }
    if (flag)
      break;
    goal_time += 60;
  }

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  long long int a, b, c;
  cin >> a >> b >> c;

  if ((60 % (a + b)) == 0) {

    if ((c % (a + b)) <= a) {
      cout << c << endl;
    } else {
      cout << -1 << endl;
    }

  } else {

    for (long long int t = 0;; t++) {

      if (((c + 60 * t) % (a + b)) <= a) {

        cout << c + 60 * t << endl;
        break;

      } else if (t > 60) {
        cout << -1 << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  long long int a, b, c;
  cin >> a >> b >> c;

  if ((60 % (a + b)) == 0) {

    if ((c % (a + b)) <= a) {
      cout << c << endl;
    } else {
      cout << -1 << endl;
    }

  } else {

    for (long long int t = 0;; t++) {

      if (((c + 60 * t) % (a + b)) <= a) {
        cout << c + 60 * t << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int st, et, r;
  int d[60] = {};
  for (st = r = 0, et = a;; d[st] = et, st = et + b, et = st + a) {
    if (st >= 60) {
      st -= 60;
      et -= 60;
      r++;
    }
    if (c >= st && c <= et) {
      cout << r * 60 + c << endl;
      break;
    }
    if (d[st] == et) {
      cout << "-1" << endl;
      break;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int st, et, r;
  int d[60] = {};
  for (st = r = 0, et = a;; st = et + b, et = st + a, d[st] = et) {
    if (st >= 60) {
      st -= 60;
      et -= 60;
      r++;
    }
    if (c >= st && c <= et) {
      cout << r * 60 + c << endl;
      break;
    }
    if (d[st] == et) {
      cout << "-1" << endl;
      break;
    }
  }
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>

using namespace std;
typedef pair<int, int> P;
static const int INF = 1e9;

void solve() {
  int a[2], c;
  cin >> a[0] >> a[1] >> c;
  if (a[0] >= c) {
    cout << c << endl;
    return;
  }
  set<P> Set;
  int diff = INF;
  int now = a[0];
  int cnt = 0;
  while (true) {
    int preDiff = diff;
    diff = c - now;
    if (Set.find(make_pair(diff, preDiff)) != Set.end()) {
      cout << -1 << endl;
      return;
    }
    Set.insert(P(diff, preDiff));
    while (now < c) {
      ++cnt;
      now += a[cnt % 2];
      if (now >= c) {
        if (cnt % 2 == 1) {
          break;
        } else {
          cout << c << endl;
          return;
        }
      }
    }
    c += 60;
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
static const int INF = 1e9;

void solve() {
  int a[2], c;
  cin >> a[0] >> a[1] >> c;
  if (a[0] >= c) {
    cout << c << endl;
    return;
  }
  int diff = INF;
  int now = a[0];
  int cnt = 0;
  while (true) {
    int preDiff = diff;
    diff = c - now;
    if (preDiff == diff) {
      cout << -1 << endl;
      return;
    }
    while (now < c) {
      ++cnt;
      now += a[cnt % 2];
      if (now >= c) {
        if (cnt % 2 == 1) {
          break;
        } else {
          cout << c << endl;
          return;
        }
      }
    }
    c += 60;
  }
}

int main() {
  solve();
  return (0);
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define reep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) reep((i), 0, (n))

typedef long long ll;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll t = 0;
  while (1) {
    if (c < (a + b) * t) {
      c += 60;
    } else if (c <= (a + b) * t + a) {
      cout << c << endl;
      return 0;
    } else {
      t++;
    }
    if (t > 1000)
      break;
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define reep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) reep((i), 0, (n))

typedef long long ll;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll t = 0;
  while (1) {
    if (c < (a + b) * t) {
      c += 60;
    } else if (c <= (a + b) * t + a) {
      cout << c << endl;
      return 0;
    } else {
      t++;
    }
  }
  cout << -1 << endl;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <climits>
#include <iostream>
#define ll long long
using namespace std;

int main() {
  int a, b;
  ll c, time = 0;

  cin >> a >> b >> c;

  while (1) {
    if (c >= INT_MAX) {
      c = -1;
      break;
    }
    time += a;
    if (time >= c)
      break;
    time += b;
    if (time >= c)
      c += 60;
  }

  cout << c << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int func_J(int a, int b, int time) {
  if (time <= a)
    return 1;

  time = time - (a + b);
  if (time > 0)
    return func_J(a, b, time);
  else if (time < 0)
    return 0;
  else
    return 1;
}

int func(int a, int b, int c, int d) {
  int time;

  time = 60 - b + c - a;
  d += 60;
  if (time <= a || func_J(a, b, time) == 1)
    return d;
  else
    func(a, b, time, d);

  return 0;
}

int main() {
  int a, b, c;
  int rel = 0;

  cin >> a >> b >> c;

  if (a >= c)
    rel = c;
  else if (a == b && a < c)
    rel = -1;
  else if (c > a + b) {
    if (func_J(a, b, c) == 1)
      rel = c;
    else
      rel += func(a, b, c, c);
  } else
    rel += func(a, b, c, c);

  cout << rel << endl;

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  for (int i = 0;; i += a + b) {
    if (i <= c && c <= i + a) {
      cout << i + c % 60 - i % 60 << endl;
      break;
    }
    // if(60<i && 60%(a+b)==0){
    if (100000 < i) {
      cout << -1 << endl;
      break;
    }
    if (i / 60 != (i + a + b) / 60)
      c += 60;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  for (int i = 0;; i += a + b) {
    if (i <= c && c <= i + a) {
      cout << i + c % 60 - i % 60 << endl;
      break;
    }
    if (60 < i && 60 % (a + b) == 0) {
      cout << -1 << endl;
      break;
    }
    if (i / 60 != (i + a + b) / 60)
      c += 60;
  }

  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int a, b, c, n = 1, T[4000];

  cin >> a >> b >> c;
  while (n < 4000) {
    for (int i = 0; i < a; i++, n++)
      T[n] = 1;
    for (int i = 0; i < b; i++, n++)
      T[n] = 0;
    if (n > 3800)
      break;
  }

  for (int i = c; i < 4000; i += 60) {
    if (T[i] == 1) {
      cout << i << endl;
      break;
    }
    if (i > 3600) {
      cout << "-1" << endl;
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c, n = 1, T[4000];

  cin >> a >> b >> c;
  while (n < 4000) {
    for (int i = 0; i < a; i++, n++)
      T[n] = 1;
    for (int i = 0; i < b; i++, n++)
      T[n] = 0;
  }
  for (int i = c; i < 4000; i += 60) {
    if (T[i] == 1) {
      cout << i << endl;
      break;
    }
    if (i > 3600) {
      cout << -1 << endl;
      break;
    }
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
bool vis[120];
int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int mod = c % (a + b);
  if (mod <= a)
    printf("%d\\n", c);
  else {
    int ans = c;
    while (mod % (a + b) > a) {
      vis[mod] = 1;
      mod = (mod + 60) % (a + b);
      ans += 60;
      if (vis[mod])
        break;
    }
    if (mod <= a)
      printf("%d\\n", ans);
    else
      printf("-1\\n");
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int mod = c % (a + b);
  if (mod <= a)
    printf("%d\\n", c);
  else if (60 % (a + b) == 0)
    printf("-1\\n");
  else {
    int ans = c;
    while (mod % (a + b) > a)
      mod = (mod + 60) % (a + b), ans += 60;
    printf("%d\\n", ans);
  }
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
typedef pair<int, int> P;

//-----------------------------------------------------------------------

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, c;
  cin >> a >> b >> c;
  int l = 0, r = a;
  REP(i, 1e5) {
    while (c < l)
      c += 60;
    if (c <= r) {
      cout << c << endl;
      return 0;
    } else {
      l += a + b, r += a + b;
    }
  }
  cout << -1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
typedef pair<int, int> P;

//-----------------------------------------------------------------------

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, c;
  cin >> a >> b >> c;
  if (c <= a)
    cout << c << endl;
  else if (a + b == 60)
    cout << -1 << endl;
  else {
    int l = a + b, r = 2 * a + b;
    while (true) {
      while (c < l)
        c += 60;
      if (c <= r) {
        cout << c << endl;
        break;
      } else {
        l += a + b, r += a + b;
      }
    }
  }
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  int d = 0;
  int n = 0;
  cin >> a >> b >> c;
  while (true) {
    if (d <= c && c <= d + a) {
      cout << n * 60 + c << endl;
      break;
    }
    d += a + b;
    if (d >= 60) {
      n += d / 60;
      d %= 60;
    }
    if (d == 0) {
      cout << -1 << endl;
      break;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  int d = 0;
  int n = 0;
  cin >> a >> b >> c;
  while (true) {
    if (d <= c && c <= d + a) {
      cout << n * 60 + c << endl;
      break;
    }
    d += a + b;
    if (d > 60) {
      n += d / 60;
      d %= 60;
    }
    if (d == 0) {
      cout << -1 << endl;
      break;
    }
  }
}
Problem p01752 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int dir[] = {0, 1, 0, -1};
int H, W;
string s[55];
bool vis[55][55];
int main() {
  cin >> H >> W;
  s[0] = s[H + 1] = string(W + 2, '#');
  for (int i = 1; i <= H; i++)
    cin >> s[i], s[i] = '#' + s[i] + '#';
  H += 2;
  W += 2;
  int x = -1, y = -1, d = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '>')
        x = i, y = j, d = 0;
      if (s[i][j] == 'v')
        x = i, y = j, d = 1;
      if (s[i][j] == '<')
        x = i, y = j, d = 2;
      if (s[i][j] == '^')
        x = i, y = j, d = 3;
    }
  }
  vis[x][y] = true;
  int cnt = 0;
  while (cnt++ < 100000) {
    int tx = x + dir[d], ty = y + dir[d ^ 1];
    if (s[tx][ty] == '#')
      d = (d + 3) & 3;
    else {
      x = tx, y = ty;
      vis[x][y] = true;
      if (s[x][y] == 'G')
        break;
      int ux = x + dir[(d + 1) & 3], uy = y + dir[((d + 1) & 3) ^ 1];
      if (s[ux][uy] != '#')
        x = ux, y = uy, d = (d + 1) & 3, vis[x][y] = true;
      if (s[x][y] == 'G')
        break;
    }
  }
  if (cnt >= 100000) {
    cout << -1 << endl;
    return 0;
  }
  int ret = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vis[i][j])
        ret++;
    }
  }
  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int dir[] = {0, 1, 0, -1};
int H, W;
string s[55];
bool vis[55][55];
int main() {
  cin >> H >> W;
  s[0] = s[H + 1] = string(W + 2, '#');
  for (int i = 1; i <= H; i++)
    cin >> s[i], s[i] = '#' + s[i] + '#';
  H += 2;
  W += 2;
  int x = -1, y = -1, d = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '>')
        x = i, y = j, d = 0;
      if (s[i][j] == 'v')
        x = i, y = j, d = 1;
      if (s[i][j] == '<')
        x = i, y = j, d = 2;
      if (s[i][j] == '^')
        x = i, y = j, d = 3;
    }
  }
  vis[x][y] = true;
  while (true) {
    int tx = x + dir[d], ty = y + dir[d ^ 1];
    if (s[tx][ty] == '#')
      d = (d + 3) & 3;
    else {
      x = tx, y = ty;
      vis[x][y] = true;
      if (s[x][y] == 'G')
        break;
      int ux = x + dir[(d + 1) & 3], uy = y + dir[((d + 1) & 3) ^ 1];
      if (s[ux][uy] != '#')
        x = ux, y = uy, d = (d + 1) & 3, vis[x][y] = true;
    }
  }
  int ret = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vis[i][j])
        ret++;
    }
  }
  cout << ret << endl;
  return 0;
}