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

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/*--------switch header--------*/
#define ALGORITHM 1
#define CASSERT 1
#define CMATH 1
#define DEQUE 1
#define FUNCTIONAL 1
#define IOMANIP 1
#define IOSTREAM 1
#define LIST 1
#define MAP 1
#define QUEUE 1
#define SET 1
#define STRING 1
#define UTILITY 1
#define VECTOR 1
#define VEC_DEBUG 1

using namespace std;

#pragma region headers
#if VEC_DEBUG
#define _GLIBCXX_DEBUG
#endif
#if ALGORITHM
#include <algorithm>
#endif
#if CASSERT
#include <cassert>
#endif
#if CMATH
#include <cmath>
#endif
#if DEQUE
#include <deque>
#endif
#if FUNCTIONAL
#include <functional>
#endif
#if IOMANIP
#include <iomanip>
#endif
#if IOSTREAM
#include <iostream>
#endif
#if LIST
#include <list>
#endif
#if MAP
#include <map>
#endif
#if QUEUE
#include <queue>
#endif
#if SET
#include <set>
#endif
#if STRING
#include <string>
#endif
#if UTILITY
#include <utility>
#endif
#if VECTOR
#include <vector>
#endif
#pragma endregion

/*----------macros----------*/

// output================
#define endl '\\n'
#define fcout cout << fixed << setprecision(15)

// typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

// const number==========
constexpr ll INF9 = (ll)1e9 + 1;
constexpr ll INF18 = (ll)1e18 + 1;
constexpr ll MOD = 1000000007;
constexpr ld PI = 3.141592653589793L;

// member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

// others================
#define ALL(x) (x).begin(), (x).end()
#define rALL(x) (x).rbegin(), (x).rend()
#define REP(i, n) for (int i = 0; (i) < (n); (i)++)
#define rREP(i, n) for (int i = n - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int i = (a); (i) < (b); (i)++)
#define CtoI(c) int((c)) - int('0')

// functions=============
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

// vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

/*----------main------------*/

int main() {
  /*----------fastio----------*/
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);
  /*----------solve-----------*/

  int n;
  cin >> n;
  int ans[n + 1];
  REP(i, n + 1) ans[i] = 0;
  FOR(i, 1, 101)
  FOR(j, 1, 101)
  FOR(k, 1, 101) {
    int s = i * i + j * j + k * k + i * j + j * k + k * i;
    if (s <= n)
      ans[s]++;
  }

  FOR(i, 1, n + 1) cout << ans[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

/*--------switch header--------*/
#define ALGORITHM 1
#define CASSERT 1
#define CMATH 1
#define DEQUE 1
#define FUNCTIONAL 1
#define IOMANIP 1
#define IOSTREAM 1
#define LIST 1
#define MAP 1
#define QUEUE 1
#define SET 1
#define STRING 1
#define UTILITY 1
#define VECTOR 1
#define VEC_DEBUG 1

using namespace std;

#pragma region headers
#if VEC_DEBUG
#define _GLIBCXX_DEBUG
#endif
#if ALGORITHM
#include <algorithm>
#endif
#if CASSERT
#include <cassert>
#endif
#if CMATH
#include <cmath>
#endif
#if DEQUE
#include <deque>
#endif
#if FUNCTIONAL
#include <functional>
#endif
#if IOMANIP
#include <iomanip>
#endif
#if IOSTREAM
#include <iostream>
#endif
#if LIST
#include <list>
#endif
#if MAP
#include <map>
#endif
#if QUEUE
#include <queue>
#endif
#if SET
#include <set>
#endif
#if STRING
#include <string>
#endif
#if UTILITY
#include <utility>
#endif
#if VECTOR
#include <vector>
#endif
#pragma endregion

/*----------macros----------*/

// output================
#define endl '\\n'
#define fcout cout << fixed << setprecision(15)

// typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

// const number==========
constexpr ll INF9 = (ll)1e9 + 1;
constexpr ll INF18 = (ll)1e18 + 1;
constexpr ll MOD = 1000000007;
constexpr ld PI = 3.141592653589793L;

// member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

// others================
#define ALL(x) (x).begin(), (x).end()
#define rALL(x) (x).rbegin(), (x).rend()
#define REP(i, n) for (int i = 0; (i) < (n); (i)++)
#define rREP(i, n) for (int i = n - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int i = (a); (i) < (b); (i)++)
#define CtoI(c) int((c)) - int('0')

// functions=============
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

// vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

int cnt_f(int _n) {
  int cnt = 0;
  FOR(i, 1, 108) FOR(j, 1, 108) FOR(k, 1, 108) {
    if (i * i + j * j + k * k + i * j + j * k + k * i == _n)
      cnt++;
  }

  return cnt;
}

/*----------main------------*/

int main() {
  /*----------fastio----------*/
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);
  /*----------solve-----------*/

  int n;
  cin >> n;

  FOR(i, 1, n + 1) { cout << cnt_f(i) << endl; }

  return 0;
}