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

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable ":\\t" << (variable) << endl
#define LOGCON(i, container)                                                   \\
  for (int(i) = 0; (i) < (container).size(); ++(i))                            \\
  cout << (i) << ":\\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)       // from n to 0
#define REPRS(i, n, r) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj)                                                       \\
  for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj)                                                      \\
  for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int in() {
  int x;
  cin >> x;
  return x;
}
string stin() {
  string s;
  cin >> s;
  return s;
}
int pp(int n) { return n * n * n * n * n; }
/***** MAIN *****/
signed main() {
  int n = in();
  REP(a, 1000) {
    REPS(b, -1000, 1000) {
      if (pp(a) - pp(b) == n) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable ":\\t" << (variable) << endl
#define LOGCON(i, container)                                                   \\
  for (int(i) = 0; (i) < (container).size(); ++(i))                            \\
  cout << (i) << ":\\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)       // from n to 0
#define REPRS(i, n, r) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj)                                                       \\
  for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj)                                                      \\
  for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int in() {
  int x;
  cin >> x;
  return x;
}
string stin() {
  string s;
  cin >> s;
  return s;
}
/***** MAIN *****/
signed main() {
  int x = in();
  for (int i = 0;; ++i) {
    int tmp = x - pow(i, 5);
    int j = 0;
    while (pow(j, 5) <= tmp) {
      ++j;
    }
    if (pow(j - 1, 5) == tmp) {
      if (i) {
        cout << j - 1 << " -" << i << endl;
      } else {
        cout << i << " -" << j - 1 << endl;
      }
      return 0;
    }
  }
  cout << "\\n";
  return 0;
}
/***** MAIN *****/