Problem p02608 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

int calc_left(int x, int y, int z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}

int calc_comb_count(int x, int y, int z) {
  if (x == y) {
    if (y == z) {
      return 1;
    } else {
      return 3;
    }
  } else {
    if (y == z) {
      return 3;
    } else {
      return 6;
    }
  }
}

vector<int> solve(int N) {
  int x_max = sqrt(N / 6);
  vector<int> retv(N, 0);

  for (int x = 1; x <= x_max; x++) {
    bool is_y_excced = false;
    int y = x;
    while (!is_y_excced) {
      bool is_z_excced = false;
      int z = y;
      while (!is_z_excced) {
        int lhs = calc_left(x, y, z);
        if (lhs > N) {
          is_z_excced = true;
          if (y == z) {
            is_y_excced = true;
          }
        } else {
          retv[lhs - 1] += calc_comb_count(x, y, z);
          z++;
        }
      }
      y++;
    }
  }
  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  // main procedure
  vector<int> ans = solve(N);

  // output
  for (int n = 1; n <= N; n++) {
    cout << ans[n - 1] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

int calc_left(int x, int y, int z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}

int calc_comb_count(int x, int y, int z) {
  if (x == y) {
    if (y == z) {
      return 1;
    } else {
      return 3;
    }
  } else {
    if (y == z) {
      return 3;
    } else {
      return 6;
    }
  }
}

vector<int> solve(int N) {
  int x_max = sqrt(N / 6);
  vector<int> retv(N, 0);

  for (int x = 1; x <= x_max; x++) {
    bool is_y_excced = false;
    int y = x;
    while (!is_y_excced) {
      bool is_z_excced = false;
      int z = y;
      while (!is_z_excced) {
        int lhs = calc_left(x, y, z);
        if (lhs > N) {
          is_z_excced = true;
          if (y == z) {
            is_y_excced = true;
          }
        }
        retv[lhs - 1] += calc_comb_count(x, y, z);
        z++;
      }
      y++;
    }
  }
  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  // main procedure
  vector<int> ans = solve(N);

  // output
  for (int n = 1; n <= N; n++) {
    cout << ans[n - 1] << endl;
  }

  return 0;
}