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

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define tc                                                                     \\
  int tcs;                                                                     \\
  cin >> tcs;                                                                  \\
  while (tcs--)
const int N = 10002;
const int MOD = 1e9 + 7;
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define trace4(a, b, c, d)                                                     \\
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \\
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define printclock                                                             \\
  cerr << "Time : " << 1000 * (int)clock() / (int)CLOCKS_PER_SEC << "ms\\n"
vector<int> v(N, 0);
void solve() {
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 100; j++) {
      for (int k = 1; k <= 100; k++) {
        int val = i * i + j * j + k * k + i * j + j * k + k * i;
        if (val > 10000)
          continue;
        v[val]++;
      }
    }
  }
}
int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
   * int overflow, array bounds
   * special cases (n=1?)
   * do smth instead of nothing and stay organized
   */
  int n;
  cin >> n;
  solve();
  for (int i = 1; i <= n; i++) {
    cout << v[i] << endl;
  }

  cout << endl;
  printclock;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define tc                                                                     \\
  int tcs;                                                                     \\
  cin >> tcs;                                                                  \\
  while (tcs--)
const int N = 200007;
const int MOD = 1e9 + 7;
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
int a[N], b[N];
vector<int> v(N);
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define trace4(a, b, c, d)                                                     \\
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \\
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define printclock                                                             \\
  cerr << "Time : " << 1000 * (int)clock() / (int)CLOCKS_PER_SEC << "ms\\n"

int fun(int n) {
  int count = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    for (int j = 1; j <= sqrt(n); j++) {
      for (int k = 1; k <= sqrt(n); k++)
        if (i * i + j * j + k * k + i * j + k * j + k * i == n) {
          // cout<<i<<j<<k<<endl;
          count++;
        }
    }
  }
  return count;
}
int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
   * int overflow, array bounds
   * special cases (n=1?)
   * do smth instead of nothing and stay organized
   */

  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i = 1; i <= 5; i++) {
    v[i] = 0;
  }
  v[6] = 1;
  for (int i = 7; i <= n; i++) {
    int x = fun(i);
    v[i] = x;
  }
  for (int i = 1; i <= n; i++) {
    cout << v[i] << endl;
  }

  cout << endl;
  printclock;
}