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

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

#define REP(i, n) for (int64_t i = 0; i < n; i++)
#define REPR(i, n) for (int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for (int64_t i = m; i < n; i++)
#define FORR(i, m, n) for (int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll x;

int main() {
  cin >> x;
  int64_t a, b = 0, b_s = 0;
  while (true) {
    a = pow(x + pow(b_s, 5), 0.2);
    b = b_s;
    if (pow(a, 5) - pow(b, 5) == x) {
      break;
    } else {
      if (x - pow(b_s, 5) < 0) {
        a = pow(pow(b_s, 5) - x, 0.2);
      } else {
        a = pow(x - pow(b_s, 5), 0.2);
      }
      b = -1 * b_s;
      if (pow(a, 5) - pow(b, 5) == x) {
        break;
      }
    }
    b_s++;
  }
  /*
  double a = pow(x,0.2);
  ll a_r = round(a);
  bool minus = false;
  if(a_r-a<0)minus=true;
  ll b=0;
  cout << a << a_r << " " << b << endl;
  return 0;
  if(minus){
      while(true){
          if(pow(a_r,5)-pow(b,5)==x)
          {
              break;
          }
          else
          {
              b--;
          }
      }
  }
  else
  {
      while(true){
          if(pow(a_r,5)-pow(b,5)==x)
          {
              break;
          }
          else
          {
              b++;
          }
      }
  }
  cout << a_r << " " << b << endl;
  */
  cout << a << " " << b << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int64_t i = 0; i < n; i++)
#define REPR(i, n) for (int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for (int64_t i = m; i < n; i++)
#define FORR(i, m, n) for (int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll x;

int main() {
  cin >> x;
  double a = pow(x, 0.2);
  ll a_r = round(a);
  bool minus = false;
  if (a_r - a < 0)
    minus = true;
  ll b = 0;
  if (minus) {
    while (true) {
      if (pow(a_r, 5) - pow(b, 5) == x) {
        break;
      } else {
        b--;
      }
    }
  } else {
    while (true) {
      if (pow(a_r, 5) - pow(b, 5) == x) {
        break;
      } else {
        b++;
      }
    }
  }
  cout << a_r << " " << b << endl;
  return 0;
}