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

// 23
#include <bits/stdc++.h>
using namespace std;
#define coutc "\\033[48;5;196m\\033[38;5;15m"
#define endc "\\033[0m"
#define endl '\\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef DEBUG
// 3
ostream &operator<<(ostream &o, pair<auto, auto> p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 4
ostream &operator<<(ostream &o, vector<auto> v) {
  rep(i, len(v)) o << setw(7) << right << v[i];
  return o << endc << endl << coutc;
}
// 4
ostream &operator<<(ostream &o, map<auto, auto> m) {
  for (auto &kv : m)
    o << kv;
  return o;
}
// 7
void debug(const auto &e, const auto &...r) {
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
}
#else
#define debug(...)
#endif
// 3
void _main(int tc) {
  int n;
  cin >> n;
  li ans = 1;
  bool zero = false, exceeds = false;
  const li limit = 1e18;

  rep(n) {
    li x;
    cin >> x;
    if (x == 0) {
      zero = true;
      break;
    }
    if (ans > 0 && x > limit / ans) {
      exceeds = true;
    }
    ans *= x;
  }
  if (zero)
    cout << 0 << endl;
  else if (exceeds)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Error: 0

Fixed submission:

// 23
#include <bits/stdc++.h>
using namespace std;
#define coutc "\\033[48;5;196m\\033[38;5;15m"
#define endc "\\033[0m"
#define endl '\\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef DEBUG
// 3
ostream &operator<<(ostream &o, pair<auto, auto> p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 4
ostream &operator<<(ostream &o, vector<auto> v) {
  rep(i, len(v)) o << setw(7) << right << v[i];
  return o << endc << endl << coutc;
}
// 4
ostream &operator<<(ostream &o, map<auto, auto> m) {
  for (auto &kv : m)
    o << kv;
  return o;
}
// 7
void debug(const auto &e, const auto &...r) {
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
}
#else
#define debug(...)
#endif
// 3
void _main(int tc) {
  int n;
  cin >> n;
  li ans = 1;
  bool zero = false, exceeds = false;
  const li limit = 1e18;

  rep(n) {
    li x;
    cin >> x;
    if (x == 0)
      zero = true;
    if (x > limit / ans)
      exceeds = true;
    ans *= x;
    if (ans == 0)
      break;
  }
  if (exceeds && !zero)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}