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

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>     //required

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(), a.end()
#define fr(i, x, y) for (ll i = x; i < y; i++)
#define frr(i, x, y) for (ll i = x - 1; i >= y; i--)
#define inf 1e18 + 1
const ll mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve() {
  ll x;
  cin >> x;
  fr(i, -200, 200) {
    ll a = i * i * i * i * i;
    fr(j, -200, 200) {
      ll b = j * j * j * j * j;
      if (a - b == x) {
        cout << i << " " << j << endl;
        return;
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>     //required

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(), a.end()
#define fr(i, x, y) for (ll i = x; i < y; i++)
#define frr(i, x, y) for (ll i = x - 1; i >= y; i--)
#define inf 1e18 + 1
const ll mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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 point 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;
}
void solve() {
  ll x;
  cin >> x;
  fr(i, 0, 10000) {
    ll b = pow(i, 5) - x;
    ll c = floorRoot5(abs(b));
    ll z = pow(c, 5);
    if (b < 0) {
      c *= -1;
    }
    if (abs(b) == abs(z)) {
      if ((pow(i, 5) - pow(c, 5)) == x) {
        cout << i << " " << c << endl;
        return;
      }
    }
  }
  fr(i, 0, 10000) {
    ll b = pow(-i, 5) - x;
    ll c = floorRoot5(abs(b));
    ll z = pow(c, 5);
    if (b < 0) {
      c *= -1;
    }
    if (abs(b) == abs(z)) {
      if ((pow(i, 5) - pow(c, 5)) == x) {
        cout << i << " " << c << endl;
        return;
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}