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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s >= 0; s--)

int main() {
  ll n, ans = 0, a = 0, b = 0;
  string s;

  cin >> n;

  ll buf = 0;

  while (1) {
    a++;
    buf = pow(a, 5);

    ll buf2 = abs(n - buf);

    double buf3 = pow((double)buf2, 0.2);

    if (round(floor(buf3) * pow(10, 4)) == round(buf3 * pow(10, 4))) {
      if (n > buf)
        b = -buf3;
      else
        b = buf3;

      break;
    }
  }

  cout << a << " " << b;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s >= 0; s--)

int main() {
  ll n, ans = 0, a = 0, b = 0;
  string s;

  cin >> n;

  ll buf = 0;

  while (1) {
    a++;
    buf = pow(a, 5);

    if (floor(pow((double)abs(n - buf), 0.2)) ==
        pow((double)abs(n - buf), 0.2)) {
      if (n > buf)
        b = -pow((double)abs(n - buf), 0.2);
      else
        b = pow((double)abs(n - buf), 0.2);
      break;
    }
  }

  cout << a << " " << b;
}
Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
typedef long long ll;
inline int rd() {
  int x = 0, p = 1;
  char a = getchar();
  while ((a < 48 || a > 57) && a != '-')
    a = getchar();
  if (a == '-')
    p = -p, a = getchar();
  while (a > 47 && a < 58)
    x = (x << 1) + (x << 3) + (a & 15), a = getchar();
  return x * p;
}
ll x;
int main() {
  x = rd();
  for (ll a = 0; a <= 1000; a++)
    for (ll b = -1000; b <= 1000; b++)
      if ((1ll * a * a * a * a * a - 1ll * b * b * b * b * b) == x)
        return printf("%lld %lld\\n", a, b), 0;
  return 0;
}

Error: 5

Fixed submission:

#include <cstdio>
typedef long long ll;
inline int rd() {
  int x = 0, p = 1;
  char a = getchar();
  while ((a < 48 || a > 57) && a != '-')
    a = getchar();
  if (a == '-')
    p = -p, a = getchar();
  while (a > 47 && a < 58)
    x = (x << 1) + (x << 3) + (a & 15), a = getchar();
  return x * p;
}
ll x;
int main() {
  x = rd();
  for (ll a = 0; a <= 1000; a++)
    for (ll b = -1000; b <= 1000; b++)
      if ((1ll * a * a * a * a * a - 1ll * b * b * b * b * b) == x)
        return printf("%lld %lld\\n", a, b);
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Runtime Error

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

ll A[1001];

int main() {
  int x;
  cin >> x;
  for (int i = 0; i <= 1000; i++) {
    ll z = i;
    for (int j = 0; j < 4; j++)
      z *= i;
    A[i] = z;
  }

  for (int i = 0; i <= 1000; i++) {
    for (int j = i; j <= 1000; j++) {
      if (A[j] - A[i] == x) {
        cout << j << " " << i;
        return 0;
      } else if (A[j] + A[i] == x) {
        cout << j << " " << -i;
        return 0;
      }
    }
  }
}


Error: WA

Fixed submission:

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

int n;
ll sol = 0, x;
ll A[200005];
map<ll, ll> M; // diff

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    M[i - A[i]]++;
  }

  for (int i = 1; i <= n; i++) {
    x = i + A[i];
    sol += M[x];
    if (A[i] == 0)
      sol--;
  }
  cout << sol;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long; //
template <typename T> T sq(T x) { return x * x; }
signed main() {
  lint X;
  cin >> X;
  int A1, B1;
  int A2, B2;
  // cout << X << endl;
  if (X == 1) {
    cout << 0 << " " << -1 << endl;
    return 0;
  }
  for (int i = 1; i < sqrt(X); i++) {
    if (X % i == 0) {
      // cout << "i" << sqrt(X) << endl;
      rep2(j, -100, sqrt(sqrt(5 * X))) {
        // A1 = j;
        // B1 = A1 - i;
        B2 = j;
        A2 = B2 + i;
        // lint eq1 = sq(sq(A1)) + sq(sq(B1))
        lint eq2 = sq(sq(A2)) + sq(sq(B2)) + sq(A2) * sq(B2) +
                   A2 * B2 * (sq(A2) + sq(B2));
        // if(eq1 == X/i){
        //   cout << A1 << " " << B1 << endl;
        //   return 0;
        // }
        if (eq2 == X / i) {
          cout << A2 << " " << B2 << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long; //
template <typename T> T sq(T x) { return x * x; }
signed main() {
  lint X;
  cin >> X;
  int A1, B1;
  int A2, B2;
  // cout << X << endl;
  if (X == 1) {
    cout << 0 << " " << -1 << endl;
    return 0;
  }

  for (int i = 1; i < sqrt(X); i++) {
    if (X % i == 0) {
      // cout << "i" << sqrt(X) << endl;
      rep2(j, -100, X) {
        A1 = j;
        B1 = A1 - i;
        B2 = j;
        A2 = B2 + i;
        lint eq1 = sq(sq(A1)) + sq(sq(B1)) + sq(A1) * sq(B1) +
                   A1 * B1 * (sq(A1) + sq(B1));

        lint eq2 = sq(sq(A2)) + sq(sq(B2)) + sq(A2) * sq(B2) +
                   A2 * B2 * (sq(A2) + sq(B2));
        if (eq1 == X / i) {
          cout << A1 << " " << B1 << endl;
          return 0;
        }
        if (eq2 == X / i) {
          cout << A2 << " " << B2 << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

double sign;
double ans;

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

  for (ll i = 0; i <= 1000; i++) {
    for (ll j = 0; j < i; j++) {
      if (pow(i, 5) - pow(j, 5) == n) {
        cout << i << " " << j << endl;
        return 0;
      }
      if (pow(i, 5) + pow(j, 5) == n) {
        cout << i << " " << -j << endl;
        return 0;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cmath>         // sqrt
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b) {
  // Eucledean algorithm
  while (a) {
    if (a < b) {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n) {
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

vector<ll> memo;
ll multiple(ll x) {
  ll tmp = x;
  // if (memo.at(tmp) != 0)
  // {
  //   return memo.at(tmp);
  // }
  rep(i, 4) { x *= tmp; }
  // memo.at(tmp) = x;
  // return memo.at(tmp);
  return x;
}
ll dp[10][10];
Pl ans;
void solve(ll x) {
  rep(i, x) {
    rep2(j, -x, x) {
      if (multiple(i) - multiple(j) == x) {
        ans.first = i;
        ans.second = j;
        return;
      }
    }
  }
}
int main() {
  ll X;
  cin >> X;
  solve(X);
  cout << ans.first << " " << ans.second << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

ll fiv(int a, int s) { return a * a * a * a * a + s * s * s * s * s; }

int main() {
  int X;
  cin >> X;
  rep(i, 120) {
    rep(j, i + 1) {
      if (i * i * i * i * i + j * j * j * j * j == X) {
        cout << i << ' ' << -j << endl;
        return 0;
      } else if (i * i * i * i * i - j * j * j * j * j == X) {
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
}


Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

ll fiv(int a, int s) { return a * a * a * a * a + s * s * s * s * s; }

int main() {
  int X;
  cin >> X;
  unsigned int A = 0, B = INT_MAX;
  // 和
  int i = 0;
  while (fiv(i, 0) <= X) {
    A = i;
    rep(j, X) {
      ll g = fiv(A, j);
      if (g > X) {
        B = j;
        break;
      }
      if (g == X) {
        cout << A << ' ' << -j << endl;
        return 0;
      }
    }

    ++i;
  }
  // 差
  A = 1;
  B = 0;
  while (1) {
    rep(i, A) {
      ll g = fiv(A, -i);
      if (g > X) {
        break;
      }
      if (g == X) {
        cout << A << ' ' << i << endl;
        break;
      }
    }

    A++;
  }
}
Problem p02690 (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 REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main() {
  ll x;
  cin >> x;
  for (ll a = -1000; a <= 1000; a++) {
    for (ll b = -1000; b <= 1000; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main() {
  ll x;
  cin >> x;
  for (ll a = -10000; a <= 10000; a++) {
    for (ll b = -10000; b <= 10000; b++) {
      if (pow(a, 5) - pow(b, 5) == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int i, j, x;
  cin >> x;
  for (i = -2000; i <= 2000; i++) {
    for (j = -2000; j <= 2000; j++) {
      if (pow(i, 5) - pow(j, 5) == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int x, c = 0, p, q;
  long int i, j;
  cin >> x;
  for (i = 0; i <= sqrt(x); i++) {
    for (j = -sqrt(x); j <= sqrt(x); j++) {
      if (pow(i, 5) - pow(j, 5) == x) {
        c = 1;
        p = i;
        q = j;
        break;
      }
    }
  }
  if (c == 1)
    cout << p << " " << q << endl;
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) (int)x.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(a) (1ll << (a))
#define endl "\\n"
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
/*并查集
 * int f[];
 * int Find(int x){x==f[x]?return f[x]:f[x]=Find(f[x]);}
 * int join(int x,int y){if(Find(x)!=Find(y))f[Find(x)]=Find(y);}
 * 快速幂*/
int qpow(ll a, ll b, ll m) {
  ll c = 1;
  while (b) {
    if (b & 1)
      c = c * a % m;
    b >>= 1;
    a = a * a % m;
  }
  return c;
}
ll a;
const int N = 120;
ll s[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> a;
  rep(i, 1, N) { s[i] = i * i * i * i * i; }
  rep(i, -120, 120) {
    rep(j, -120, 120) {
      if (pow((ll)i, 5) - pow((ll)j, 5) == a) {
        cout << i << " " << j;
        return 0;
      }
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) (int)x.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(a) (1ll << (a))
#define endl "\\n"
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
/*并查集
 * int f[];
 * int Find(int x){x==f[x]?return f[x]:f[x]=Find(f[x]);}
 * int join(int x,int y){if(Find(x)!=Find(y))f[Find(x)]=Find(y);}
 * 快速幂*/
int qpow(ll a, ll b, ll m) {
  ll c = 1;
  while (b) {
    if (b & 1)
      c = c * a % m;
    b >>= 1;
    a = a * a % m;
  }
  return c;
}
ll dp[200006][2];
ll a[200006];
int vis[200006][2];
int n;
int dfs(ll i, ll j) {
  if (i <= 0 || i > n)
    return 0;
  if (dp[i][j] != -1)
    return dp[i][j];
  if (vis[i][j] == 1)
    return -1;
  vis[i][j] = 1;
  ll sum = 0;
  ll t;
  if (j == 1) {
    t = dfs(i + a[i], 0);
    if (t == -1)
      return -1;
    sum += (a[i] + t);
  } else {
    t = dfs(i - a[i], 0);
    if (t == -1)
      return -1;
    sum += (a[i] + t);
  }
  dp[i][j] = sum;
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  rep(i, 2, n + 1) { cin >> a[i]; }
  memset(dp, -1, sizeof(dp));
  rep(i, 1, n) {
    ll t1;
    t1 = dfs(i + 1, 0);
    if (t1 == -1)
      cout << t1 << endl;
    else
      cout << t1 + i << endl;
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define DEBUG if (0)
#define lli long long int
#define ldouble long double
using namespace std;

lli pot(lli x) { return x * x * x * x * x; }

lli bs(lli res) {
  lli lo = 0, hi = 1000;
  while (lo < hi) {
    lli mid = (lo + hi) >> 1;
    if (pot(mid) >= res)
      hi = mid;
    else
      lo = mid + 1;
  }
  if (pot(lo) == res)
    return lo;
  lo = -1000, hi = 0;
  while (lo < hi) {
    lli mid = (lo + hi + 1) >> 1;
    if (pot(mid) <= res)
      lo = mid;
    else
      hi = mid - 1;
  }
  return lo;
}

int main() {
  lli x;
  while (scanf("%lld", &x) != EOF) {
    lli a, b;
    for (a = -1000;; a++) {
      lli res = pot(a) - x;
      b = bs(res);
      DEBUG printf("\\t%lld %lld\\n", a, b);
      if (pot(b) == res)
        break;
    }
    printf("%lld %lld\\n", a, b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define DEBUG if (0)
#define lli long long int
#define ldouble long double
using namespace std;

lli pot(lli x) { return x * x * x * x * x; }

lli bs(lli res) {
  lli lo = 0, hi = 100;
  while (lo < hi) {
    lli mid = (lo + hi) >> 1;
    if (pot(mid) >= res)
      hi = mid;
    else
      lo = mid + 1;
  }
  if (pot(lo) == res)
    return lo;
  lo = -100, hi = 0;
  while (lo < hi) {
    lli mid = (lo + hi + 1) >> 1;
    if (pot(mid) <= res)
      lo = mid;
    else
      hi = mid - 1;
  }
  return lo;
}

int main() {
  lli x;
  while (scanf("%lld", &x) != EOF) {
    lli a, b;
    for (a = 0;; a++) {
      lli res = pot(a) - x;
      b = bs(res);
      DEBUG printf("\\t%lld %lld\\n", a, b);
      if (pot(b) == res)
        break;
    }
    printf("%lld %lld\\n", a, b);
  }
  return 0;
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  unsigned long long x;
  std::cin >> x;
  for (long long int i = -120; i < 120; i++)
    for (long long int j = -120; j < 120; j++) {
      long long a = i * i * i * i * i, b = j * j * j * j * j;
      if (a - b == x) {
        std::cout << i << " " << j;
        return 0;
      }
    }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main() {
  int x;
  cin >> x;
  int a = 0, b = (x / 4);
  if (b == 0) {
    cout << 0 << " " << -1;
    return 0;
  }
  int mid;
  while (a < b) {
    mid = (a + b) / 2;
    int val = pow(a, 5) + pow(b, 5);
    if (val == x)
      break;
    if (val < x) {
      a = mid;
    } else {
      b = mid;
    }
  }
  cout << b << " " << -a;

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

#include <algorithm>
#include <cfenv>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int, int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void) {
  ll x;
  cin >> x;
  ll a, b;
  ll k = x % 5;
  ll t = 0;
  while (true) {
    for (a = 1; a < 150; a++) {
      b = a - (5 * t + k);
      if (abs(b) > abs(a)) {
        continue;
      }
      if (a * a * a * a * a - b * b * b * b * b == x) {
        cout << a << ' ' << b << endl;
        return 0;
      }
    }
    t++;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfenv>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int, int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void) {
  ll x;
  cin >> x;
  ll a, b;
  ll k = x % 5;
  ll t = 1;
  while (true) {
    for (a = 1; a < 150; a++) {
      b = a - (5 * t + k);
      if (abs(b) > abs(a)) {
        continue;
      }
      if (a * a * a * a * a - b * b * b * b * b == x) {
        cout << a << ' ' << b << endl;
        return 0;
      }
    }
    t++;
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int X;
  cin >> X;
  vector<long long int> Y;
  for (long long int i = 1; i * i <= X; i++) {
    if (X % i == 0) {
      Y.push_back(i);
      if (X / i != i)
        Y.push_back(X / i);
    }
  }
  sort(Y.begin(), Y.end());
  bool finished = false;
  for (long long int i = 0; i < Y.size(); i++) {
    long long int A = 0, B = A - Y.at(i);
    while (true) {
      if (A * A * A * A * A - B * B * B * B * B == X) {
        cout << A << " " << B << endl;
        finished = true;
        break;
      } else if (B > 0 && A * A * A * A * A - B * B * B * B * B > X)
        break;
      A++;
      B++;
    }
    if (finished)
      break;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  long long int X;
  cin >> X;
  vector<long long int> Y;
  for (long long int i = 1; i * i <= X; i++) {
    if (X % i == 0) {
      Y.push_back(i);
      if (X / i != i)
        Y.push_back(X / i);
    }
  }
  sort(Y.begin(), Y.end());
  reverse(Y.begin(), Y.end());
  bool finished = false;
  for (int i = 0; i < Y.size(); i++) {
    long long int A = 0, B = A - Y.at(i);
    while (true) {
      if (A * A * A * A * A - B * B * B * B * B == X) {
        cout << A << " " << B << endl;
        finished = true;
        break;
      } else if (B > 0 && A * A * A * A * A - B * B * B * B * B > X)
        break;
      A++;
      B++;
    }
    if (finished)
      break;
  }
}
Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <unordered_set>
#include <vector>

int64_t f(int64_t num) {
  int64_t ret = 1;
  for (int i = 0; i < 5; ++i) {
    ret *= num;
  }
  return ret;
}

int main() {
  int64_t x;
  std::cin >> x;
  int64_t a = 1;
  int64_t b = 0;
  while (f(a) - f(b) != x && f(a) + f(b) != x) {
    if (f(a) - f(b) > x) {
      ++b;
    } else if (f(a) - f(b) < x && f(a) + f(b) > x) {
      ++a;
    } else {
      if (2 * f(a) < x) {
        ++a;
      } else {
        int64_t tmp = b;
        bool isOK = false;
        while (tmp < a && f(a) + f(tmp) < x) {
          ++tmp;
          if (f(a) + f(tmp) == x) {
            b = tmp;
            isOK = true;
            break;
          }
        }
        if (isOK == false) {
          ++a;
        }
      }
    }
  }
  if (f(a) - f(b) == x) {
    std::cout << a << " " << b << std::endl;
  } else {
    std::cout << a << " " << -b << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <unordered_set>
#include <vector>

int64_t f(int64_t num) {
  int64_t ret = 1;
  for (int i = 0; i < 5; ++i) {
    ret *= num;
  }
  return ret;
}

int main() {
  int64_t x;
  std::cin >> x;
  int64_t a = 1;
  int64_t b = 0;
  while (f(a) - f(b) != x && f(a) + f(b) != x) {
    if (f(a) - f(b) > x) {
      ++b;
    } else if (f(a) - f(b) < x && f(a) + f(b) > x) {
      ++a;
    } else {
      if (2 * f(a) < x || a <= b) {
        ++a;
      } else {
        ++b;
      }
    }
  }
  if (f(a) - f(b) == x) {
    std::cout << a << " " << b << std::endl;
  } else {
    std::cout << a << " " << -b << std::endl;
  }

  return 0;
}