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

#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define int long long
#define pii pair<int, int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a, b) __gcd(a, b)
#define all(v) v.begin(), v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int, vector<int>, greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v)                                                              \\
  for (auto p : v)                                                             \\
    cout << p << " ";
#define printa(a, n)                                                           \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

using namespace std;
map<int, int> mp;
void cal(int n) {
  for (int i = 1; i <= (int)sqrt(n) + 1; i++) {
    for (int j = 1; j <= (int)sqrt(n) + 1; j++) {
      for (int k = 1; k <= (int)sqrt(n) + 1; k++) {
        int res = (i * i) + (j * j) + (k * k) + (i * j) + (j * k) + (k * i);
        if (res > n) {
          break;
        }
        mp[res]++;
      }
    }
  }
}
int32_t main() {
  fast;

  int n;
  cin >> n;
  cal(n);
  for (int i = 1; i <= n; i++) {
    cout << mp[i] << "\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define int long long
#define pii pair<int, int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a, b) __gcd(a, b)
#define all(v) v.begin(), v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int, vector<int>, greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v)                                                              \\
  for (auto p : v)                                                             \\
    cout << p << " ";
#define printa(a, n)                                                           \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

using namespace std;
map<int, int> mp;
int cal(int n) {
  for (int i = 1; i <= (int)sqrt(n) + 1; i++) {
    for (int j = 1; j <= (int)sqrt(n) + 1; j++) {
      for (int k = 1; k <= (int)sqrt(n) + 1; k++) {
        int res = (i * i) + (j * j) + (k * k) + (i * j) + (j * k) + (k * i);
        mp[res]++;
      }
    }
  }
}
int32_t main() {
  fast;

  int n;
  cin >> n;
  cal(n);
  for (int i = 1; i <= n; i++) {
    cout << mp[i] << "\\n";
  }
}