Problem p02690 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, a, b) for (ll i = a; i >= b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define viii vector<pair<ll, pair<ll, ll>>>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mp(i, j) make_pair(i, j)
#define fi first
#define se second
#define input(a, n) fr(i, 0, n) cin >> a[i]
#define output(a, n) fr(i, 0, n) cout << a[i] << endl
#define dbg cout << "hurr" << endl;
#define dbg2 cout << "hurr2" << endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define tr(container, it)                                                      \\
  for (auto it = container.begin(); it != container.end(); it++)
bool compare(pair<ll, string> p1, pair<ll, string> p2) { return p2.fi > p1.fi; }
void solve() {
  ll x;
  cin >> x;
  fr(i, -500, 500) {
    fr(j, -500, 500) {
      if (pow(i, 5) - pow(j, 5) == x) {
        cout << i << " " << j << endl;
        return;
      }
    }
  }
}
int main() {
  fast;
  ll t = 1;
  // cin>>t;
  fr(zz, 1, t + 1) { solve(); }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, a, b) for (ll i = a; i >= b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define viii vector<pair<ll, pair<ll, ll>>>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mp(i, j) make_pair(i, j)
#define fi first
#define se second
#define input(a, n) fr(i, 0, n) cin >> a[i]
#define output(a, n) fr(i, 0, n) cout << a[i] << endl
#define dbg cout << "hurr" << endl;
#define dbg2 cout << "hurr2" << endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define tr(container, it)                                                      \\
  for (auto it = container.begin(); it != container.end(); it++)
bool compare(pair<ll, string> p1, pair<ll, string> p2) { return p2.fi > p1.fi; }
ll floorRoot5(ll n) {
  // Base cases
  if (n == 0 || n == 1)
    return n;

  // Do Binary Search for floor of 5th square root
  ll low = 1, high = n, ans = 0;
  while (low <= high) {
    // Find the middle poll and its power 5
    ll mid = (low + high) / 2;
    ll mid5 = mid * mid * mid * mid * mid;

    // If mid is the required root
    if (mid5 == n)
      return mid;

    // Since we need floor, we update answer when
    // mid5 is smaller than n, and move closer to
    // 5'th root
    if (mid5 < n) {
      low = mid + 1;
      ans = mid;
    } else // If mid^5 is greater than n
      high = mid - 1;
  }
  return ans;
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

void solve() {
  ll x;
  cin >> x;
  ll a, b;
  fr(i, -10000, 10001) {
    fr(j, i, 10001) {
      b = power(j, 5, md);
      a = power(i, 5, md);
      // cout<<a<<" "<<b<<endl;
      if ((b - a) == x % md) {
        cout << j << ' ' << i;
        return;
      }
    }
  }
  return;
}
int main() {
  fast;
  ll t = 1;
  // cin>>t;
  fr(zz, 1, t + 1) { solve(); }
}