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

#include <algorithm> // sort, 二分探索, etc
#include <iomanip>   // setprecision (浮動小数点の出力の誤差)
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = a, i##_len = (b); i < i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define cauto const auto &
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c)                                                                \\
  sort(all(c));                                                                \\
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const char newl = '\\n';

ll qp(ll a, ll b) {
  ll ans = 1;
  do {
    if (b & 1)
      ans *= a;
    a *= a;
  } while (b >>= 1);
  return ans;
}
ll qp(ll a, ll b, ll mod) {
  ll ans = 1;
  do {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
  } while (b >>= 1);
  return ans;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll comb(int n, int r) {
  vector<vector<ll>> v(n + 1, vector<ll>(r + 1, 0));
  for (int i = 0; i < n + 1; i++) {
    v[i][0] = 1;
    if (i < r + 1)
      v[i][i] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < min(i, r + 1); j++) {
      v[i][j] = v[i - 1][j - 1] + v[i - 1][j];
    }
  }
  return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)

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

  map<ll, ll> mp;
  map<ll, ll> pm;
  for (ll i = -1000; i < 1000; i++) {
    ll ii = i * i;
    ll iiiii = ii * ii * i;
    mp[i] = iiiii;
    pm[iiiii] = i;
  }

  ll A, B;
  for (auto &itr : mp) {
    if (itr.second + x == 0) {
      A = 0;
      B = itr.first;
      break;
    }
    if (pm[itr.second + x] != 0) {
      A = pm[itr.second + x];
      B = itr.first;
      break;
    }
  }
  cout << A << ' ' << B << newl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm> // sort, 二分探索, etc
#include <iomanip>   // setprecision (浮動小数点の出力の誤差)
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = a, i##_len = (b); i < i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define cauto const auto &
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c)                                                                \\
  sort(all(c));                                                                \\
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const char newl = '\\n';

ll qp(ll a, ll b) {
  ll ans = 1;
  do {
    if (b & 1)
      ans *= a;
    a *= a;
  } while (b >>= 1);
  return ans;
}
ll qp(ll a, ll b, ll mod) {
  ll ans = 1;
  do {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
  } while (b >>= 1);
  return ans;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll comb(int n, int r) {
  vector<vector<ll>> v(n + 1, vector<ll>(r + 1, 0));
  for (int i = 0; i < n + 1; i++) {
    v[i][0] = 1;
    if (i < r + 1)
      v[i][i] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < min(i, r + 1); j++) {
      v[i][j] = v[i - 1][j - 1] + v[i - 1][j];
    }
  }
  return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)

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

  ll a = 2;
  ll div = 1;
  while (x >= a * a) {
    if (x % a == 0) {
      div = x / a;
      break;
    } else {
      a++;
    }
  }

  a = x / div;

  ll A = 0;
  ll B;
  while (true) {
    B = A - a;
    ll right = A * A * A * A + A * A * A * B + A * A * B * B + A * B * B * B +
               B * B * B * B;
    if (right == div) {
      break;
    }
    A++;
  }

  cout << A << ' ' << B << newl;

  return 0;
}