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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m, h[100010];
  int a[100010], b[100010];

  cin >> n >> m;
  rep(i, n) { cin >> h[i]; }
  rep(i, m) { cin >> a[i] >> b[i]; }

  bool ans[100010];

  rep(i, n) { ans[i] = true; }

  rep(i, m) {
    int atai = h[a[i] - 1] - h[b[i] - 1];
    if (atai <= 0)
      ans[a[i] - 1] = false;
    if (atai >= 0)
      ans[b[i] - 1] = false;
  }

  int cnt = 0;
  rep(i, n) {
    if (ans[i] == true)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m, h[100010];
  int a[100010], b[100010];

  cin >> n >> m;
  rep(i, n) { cin >> h[i]; }
  rep(i, m) { cin >> a[i] >> b[i]; }

  bool ans[100010];

  rep(i, n) { ans[i] = true; }

  rep(j, n) {

    rep(i, m) {
      if (a[i] == j + 1 && h[a[i] - 1] <= h[b[i] - 1]) {
        ans[j] = false;
        break;
      }

      if (b[i] == j + 1 && h[a[i] - 1] >= h[b[i] - 1]) {
        ans[j] = false;
        break;
      }
    }
  }

  int cnt = 0;
  rep(i, n) {
    if (ans[i] == true)
      cnt++;
  }

  cout << cnt << endl;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

char s[50][50];
int h, w;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<vector<int>> arr(n);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int flag = 1;
    if (arr[i].size() == 0) {
      ans++;
      continue;
    }
    for (int j = 0; j < arr[i].size(); j++) {
      if (h[i] <= h[arr[i][j]]) {
        flag = 0;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

char s[50][50];
int h, w;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<vector<int>> arr(n);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int flag = 1;
    for (int j = 0; j < sizeof(arr[i]); j++) {
      if (h[i] < h[arr[i][j]]) {
        flag = 0;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
using namespace std;

typedef pair<int, int> pair;

int main() {
  int N = 0, M = 0;
  int a = 0, b = 0;
  cin >> N >> M;
  vector<ll> H(N, 0);
  vector<ll> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[a - 1] = max(A[a - 1], H[b - 1]);
    A[b - 1] = max(A[b - 1], H[a - 1]);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    // cout << A[i]<<endl;
    if (A[i] < H[i])
      ans++;
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
using namespace std;

typedef pair<int, int> pair;

int main() {
  int N, M;
  int a, b;
  cin >> N >> M;
  vector<ll> H(N, 0);
  vector<ll> A(M, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[a - 1] = max(A[a - 1], H[b - 1]);
    A[b - 1] = max(A[b - 1], H[a - 1]);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    // cout << A[i]<<endl;
    if (A[i] < H[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
void solve() {
  ll n;
  cin >> n;
  for (ll i = -1000; i < 1000; i++) {
    for (ll j = -1000; j < 1000; j++) {
      // cout<<(power(i,5,M)-power(i,5,M))%M<<"\\n";
      if ((i * i * i * i * i) - (j * j * j * j * j) == n) {
        cout << i << " " << j << "\\n";
        i = 1000;
        j = 1000;
      }
    }
  }
}
int main() {
  fast();
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
void solve() {
  ll n;
  cin >> n;
  for (ll i = -1000; i < 1000; i++) {
    for (ll j = -1000; j < 1000; j++) {
      // cout<<(power(i,5,M)-power(i,5,M))%M<<"\\n";
      if ((i * i * i * i * i) - (j * j * j * j * j) == n) {
        cout << i << " " << j << "\\n";
        i = 100;
        j = 100;
      }
    }
  }
}
int main() {
  fast();
  solve();
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll choose2(ll n) { return n * (n - 1) / 2; }

int main() {
  ll x;
  cin >> x;
  rep(i, 0, 200) {
    rep(j, 0, 200) {
      int hoge_a = -1 * i;
      int hoge_b = -1 * j;

      if (pow(i, 5) - pow(j, 5) == x) {
        cout << i << " " << j << endl;
        return 0;
      }

      else if (pow(i, 5) - pow(hoge_b, 5) == x) {
        cout << i << " " << hoge_b << endl;
        return 0;
      }

      else if (pow(hoge_a, 5) - pow(j, 5) == x) {
        cout << hoge_a << " " << j << endl;
        return 0;
      }

      else if (pow(hoge_a, 5) - pow(hoge_b, 5) == x) {
        cout << hoge_a << " " << hoge_b << endl;
        return 0;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll choose2(ll n) { return n * (n - 1) / 2; }

int main() {
  ll x;
  cin >> x;
  int piyo = pow(x, 1.0 / 5.0);
  ll a = 0, b = 0;
  while (1) {
    rep(i, 0, piyo - 1 / 2) {
      b++;
      ll hoge_b = -1 * b;
      ll hoge_a = -1 * a;
      if (pow(a, 5) - pow(b, 5) == x) {
        cout << a << " " << b << endl;
        return 0;
      }

      else if (pow(a, 5) - pow(hoge_b, 5) == x) {
        cout << a << " " << hoge_b << endl;
        return 0;
      }

      else if (pow(hoge_a, 5) - pow(b, 5) == x) {
        cout << hoge_a << " " << b << endl;
        return 0;
      }

      else if (pow(hoge_a, 5) - pow(hoge_b, 5) == x) {
        cout << hoge_a << " " << hoge_b << endl;
        return 0;
      }
    }
    b = 0;
    a++;
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  //
  long long num;
  cin >> num;

  for (long long i = -200; i <= 200; i++) {
    for (long long j = -200; j <= 200; j++) {
      if (i * i * i * i * i - j * j * j * j * j == num) {
        cout << i << " " << j;
        return 0;
      }
    }
  }

  cout << "No";
  //
}


Error: TLE

Fixed submission:

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

int main() {
  long long x;
  bool chk = true;

  long long a = 0;
  long long b = 0;
  long long tmp;

  cin >> x;

  for (int i = 0; i <= 10000; i++) {
    for (int j = 0; j <= 10000; j++) {
      tmp = pow(i, 5) - pow(j, 5);
      if (x == tmp) {
        chk = false;
        cout << i << " " << j;
        break;
      } else if (x < tmp) {
        break;
      }
    }
    if (chk == false)
      break;

    for (int j = 0; j >= -10000; j--) {
      tmp = pow(i, 5) - pow(j, 5);
      if (x == tmp) {
        chk = false;
        cout << i << " " << j;
        break;
      } else if (x < tmp) {
        break;
      }
    }
    if (chk == false)
      break;
  }
}
Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll x;
  cin >> x;

  for (ll a = -2000; a <= 2000; a++) {
    for (ll b = -2000; b <= 2000; b++) {
      if (a * a * a * a * a - b * b * b * b * b == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Error: -6
free(): invalid pointer


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x;
  cin >> x;
  vector<int> arr(83);
  for (int i = -39; i <= 39; i++) {
    // arr[i] = i * i * i * i * i;
    arr[i] = pow(i, 5);
  }

  for (int a = -39; a <= 39; a++) {
    for (int b = -39; b <= 39; b++) {
      if (arr[a] - arr[b] == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <cfenv>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;

ll pow5(ll x) { return x * x * x * x * x; }

int main() {
  ll x;
  cin >> x;

  for (ll i = 1; i < 200; i++) {
    for (ll j = 0; j < 200; j++) {
      for (ll k = 0; k < 200; k++) {
        if (pow5(j) - pow5(k - i) == x) {
          println(j << " " << k - i);
          return 0;
        }
      }
    }
  }
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <cfenv>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;

ll pow5(ll x) { return x * x * x * x * x; }

int main() {
  ll x;
  cin >> x;

  for (ll i = 0;; i++) {
    ll b = abs(pow5(i) - x);
    double b0 = pow((double)b, 0.2);
    if (ceil(b0) == floor(b0)) {
      println(i << " " << -(ll)b0);
      break;
    }
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll X;

ll pow_5(ll i) { return i * i * i * i * i; }

int main() {
  cin >> X;

  for (int i = -119; i < 200; i++) {
    for (int j = -119; j < 200; j++) {
      if (pow_5(i) - pow_5(j) == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}


Error: TLE

Fixed submission:

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

ll X;

ll hint(ll num) {
  for (ll i = num + 1; i < X; i++) {
    if (X % i == 0) {
      return i;
    }
  }
}

ll pow_5(ll i) { return i * i * i * i * i; }

int main() {
  cin >> X;
  if (X == 1) {
    cout << 0 << " " << -1 << endl;
    return 0;
  }

  ll cnt = 1;

  while (1) {
    ll hint_tmp = hint(cnt);
    ll tmp = 0;
    for (ll i = 0; i <= X; i++) {

      if (pow_5(i) - pow_5(i - hint_tmp) == X) {
        cout << i << " " << i - hint_tmp << endl;
        return 0;
      }
    }

    cnt = hint_tmp;
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long x;
  cin >> x;
  for (long long i = -1000; i * i * i < x; i++) {
    for (long long j = 100000; j * j * j > -1000000000; j--) {
      if (i * i * i * i * i - j * j * j * j * j == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long x;
  cin >> x;
  for (long long i = 0; i * i * i * i * i < x; i++) {
    for (long long j = 0; j * j * j * j * j < 1000000000; j--) {
      if (i * i * i * i * i - j * j * j * j * j == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(int argc, char const *argv[]) {
  int x;
  cin >> x;

  for (long long a = -200; a <= 200; a++) {
    for (long long b = -200; b <= 200; b++) {
      if (a * a * a * a * a - b * b * b * b * b == x) {
        cout << a << ' ' << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main(int argc, char const *argv[]) {
  int x;
  cin >> x;

  int A;
  int B = 0;
  bool ok = false;
  while (true) {
    int a = x + pow(B, 5);
    for (size_t i = 1; pow(i, 5) <= a; i++) {
      if (a % i == 0 && pow(i, 5) == a) {
        ok = true;
        A = i;
        break;
      }
    }
    a = x - pow(B, 5);
    for (size_t i = 1; pow(i, 5) <= a; i++) {
      if (a % i == 0 && pow(i, 5) == a) {
        ok = true;
        A = i;
        B = -B;
        break;
      }
    }
    if (ok)
      break;
    else
      B++;
  }

  cout << A << ' ' << B << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <fstream>
#include <vector>

using namespace std;

int main(void) {

  long long x;
  long long data[3000];

  cin >> x;

  for (int i = 0; i < 3000; i++) {
    data[i] = pow(i, 5);
  }

  for (int a = 0; a < 3000; a++) {
    for (int b = 0; b < 3000; b++) {
      if (data[a] - data[b] == x) {
        cout << a << " " << b;
        return 0;
      }
      if (data[a] + data[b] == x) {
        cout << a << " " << -b;
        return 0;
      }
      if (-data[a] - data[b] == x) {
        cout << -a << " " << b;
        return 0;
      }
      if (-data[a] + data[b] == x) {
        cout << -a << " " << -b;
        return 0;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <fstream>
#include <vector>

using namespace std;

int main(void) {

  long long a, b, aa, bb, x;

  cin >> x;

  a = b = 0;

  if (x % 2 == 0) {
    a = pow(x, 0.2);

    while (1) {
      for (long long i = (a % 2 == 0) ? 0 : 1; i < a; i += 2) {
        b = i;
        aa = pow(a, 5);
        bb = pow(b, 5);

        if (aa - bb == x) {
          cout << a << " " << b;
          return 0;
        } else if (aa - bb < x) {

          b *= -1;
          if (aa + bb == x) {
            cout << a << " " << b;
            return 0;
          }
          b *= -1;

        } else {
          a *= -1;
          if (-aa - bb == x) {
            cout << a << " " << b;
            return 0;
          }

          b *= -1;
          if (-aa + bb == x) {
            cout << a << " " << b;
            return 0;
          }

          a *= -1;
          b *= -1;
        }
      }
      a++;
    }
  } else {
    a = pow(x, 0.2);
    while (1) {
      for (long long i = (a % 2 == 1) ? 0 : 1; i < a; i += 2) {
        b = i;
        aa = pow(a, 5);
        bb = pow(b, 5);

        if (aa - bb == x) {
          cout << a << " " << b;
          return 0;
        } else if (aa - bb < x) {

          b *= -1;
          if (aa + bb == x) {
            cout << a << " " << b;
            return 0;
          }
          b *= -1;

        } else {
          a *= -1;
          if (-aa - bb == x) {
            cout << a << " " << b;
            return 0;
          }

          b *= -1;
          if (-aa + bb == x) {
            cout << a << " " << b;
            return 0;
          }

          a *= -1;
          b *= -1;
        }
      }
      a++;
    }
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {
  ll x;
  cin >> x;
  ll root = pow(x, 1 / 5);

  ll ans_a = 0;
  ll ans_b = 0;
  bool flg = false;

  rep(i, 10000) {
    rep(j, 10000) {
      if (x >= pow(root + i, 5) - pow(j, 5) &&
          x <= pow(root - i, 5) - pow(-j, 5))
        break;

      if (x == pow(root + i, 5) - pow(j, 5)) {
        ans_a = root + i;
        ans_b = j;
        flg = true;
      }
      if (x == pow(root + i, 5) - pow(-j, 5)) {
        ans_a = root + i;
        ans_b = -j;
        flg = true;
      }
      if (x == pow(root - i, 5) - pow(j, 5)) {
        ans_a = root - i;
        ans_b = j;
        flg = true;
      }
      if (x == pow(root - i, 5) - pow(-j, 5)) {
        ans_a = root - i;
        ans_b = -j;
        flg = true;
      }
      if (flg)
        break;
    }
    if (flg)
      break;
  }

  cout << ans_a << " " << ans_b << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {
  ll x;
  cin >> x;
  ll root = pow(x, 1 / 5);

  ll ans_a = 0;
  ll ans_b = 0;
  bool flg = false;

  rep(i, 100000) {
    rep(j, 100000) {
      // if(x>=pow(root+i, 5)-pow(j, 5) && x<=pow(root+i, 5)-pow(-j, 5))break;

      if (x == pow(root + i, 5) - pow(j, 5)) {
        ans_a = root + i;
        ans_b = j;
        flg = true;
      }
      if (x == pow(root + i, 5) - pow(-j, 5)) {
        ans_a = root + i;
        ans_b = -j;
        flg = true;
      }
      if (x == pow(root - i, 5) - pow(j, 5)) {
        ans_a = root - i;
        ans_b = j;
        flg = true;
      }
      if (x == pow(root - i, 5) - pow(-j, 5)) {
        ans_a = root - i;
        ans_b = -j;
        flg = true;
      }
      if (flg)
        break;
    }
    if (flg)
      break;
  }

  cout << ans_a << " " << ans_b << endl;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;

int main() {
  ll x;
  cin >> x;
  ll ansa = 0, ansb = 0;
  for (ll i = 0; i < 1000; i++) {
    for (ll j = 0; j < 1000; j++) {
      if (pow(i, 5) - pow(j, 5) == x) {
        ansa = i;
        ansb = j;
        break;
      } else if (pow(i, 5) + pow(j, 5) == x) {
        ansa = i;
        ansb = 0 - j;
        break;
      }
    }
  }
  cout << ansa << ' ' << ansb << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

int main() {
  ll x;
  cin >> x;
  ll ansa = 0, ansb = 0;
  for (ll i = 0; i < 10000; i++) {
    for (ll j = 0; j < 10000; j++) {
      if (pow(i, 5) - pow(j, 5) == x) {
        ansa = i;
        ansb = j;
        break;
      } else if (pow(i, 5) + pow(j, 5) == x) {
        ansa = i;
        ansb = 0 - j;
        break;
      }
    }
  }
  cout << ansa << ' ' << ansb << endl;
}