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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(a) a.begin(), a.end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a)                                                                \\
  rep(_X, sz(a)) { printf("%d ", a[_X]); }                                     \\
  puts("");
#define DBG2(a)                                                                \\
  rep(_X, sz(a)) {                                                             \\
    rep(_Y, sz(a[_X])) printf("%d ", a[_X][_Y]);                               \\
    puts("");                                                                  \\
  }
#define bitcount(b) __builtin_popcount(b)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

#define delete(a, n) a.erase(remove(all(a), n), a.end())
template <typename T, typename S> vector<T> &operator<<(vector<T> &a, S b) {
  a.push_back(b);
  return a;
}
template <typename T> void operator>>(vector<T> &a, int b) {
  while (b--)
    if (!a.empty())
      a.pop_back();
}
bool isprime(int n) {
  if (n < 2)
    return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
ll b_pow(ll x, ll n) { return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll; }
string itos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}

typedef unsigned int uint;
int in() {
  int x = 0, c;
  for (; (uint)((c = getchar()) - '0') >= 10;) {
    if (c == '-')
      return -in();
    if (!~c)
      throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((uint)((c = getchar()) - '0') < 10);
  return x;
}

int solve(int S) {
  for (int i = 1; i <= S; i++) {
    if (S < (3 * i + 1) || (i > (S - i) / (2 * i + 1))) {
      break;
    }
    if ((S - i) % (2 * i + 1) == 0) {
      // cout << i << " " << (S-i)/(2*i+1) << " " <<
      // i+(S-i)/(2*i+1)+2*i*(S-i)/(2*i+1) << " " << S << endl;
      return 0;
    }
  }
  return 1;
}
int dp[10000] = {};
int main() {
  int n = in();
  int ans = 0;
  while (n--) {
    int t = in();
    ans += solve(t);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(a) a.begin(), a.end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a)                                                                \\
  rep(_X, sz(a)) { printf("%d ", a[_X]); }                                     \\
  puts("");
#define DBG2(a)                                                                \\
  rep(_X, sz(a)) {                                                             \\
    rep(_Y, sz(a[_X])) printf("%d ", a[_X][_Y]);                               \\
    puts("");                                                                  \\
  }
#define bitcount(b) __builtin_popcount(b)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

#define delete(a, n) a.erase(remove(all(a), n), a.end())
template <typename T, typename S> vector<T> &operator<<(vector<T> &a, S b) {
  a.push_back(b);
  return a;
}
template <typename T> void operator>>(vector<T> &a, int b) {
  while (b--)
    if (!a.empty())
      a.pop_back();
}
bool isprime(int n) {
  if (n < 2)
    return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
ll b_pow(ll x, ll n) { return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll; }
string itos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}

typedef unsigned int uint;
int in() {
  int x = 0, c;
  for (; (uint)((c = getchar()) - '0') >= 10;) {
    if (c == '-')
      return -in();
    if (!~c)
      throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((uint)((c = getchar()) - '0') < 10);
  return x;
}

int solve(int S) {
  for (int i = 1; i <= S; i++) {
    if (S < (3 * i + 1)) {
      break;
    }
    if ((S - i) % (2 * i + 1) == 0) {
      // cout << i << " " << (S-i)/(2*i+1) << " " <<
      // i+(S-i)/(2*i+1)+2*i*(S-i)/(2*i+1) << " " << S << endl;
      return 0;
    }
  }
  return 1;
}
int main() {
  int n = in();
  int ans = 0;
  while (n--) {
    int t = in();
    ans += solve(t);
  }
  cout << ans << endl;
}