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

// written by: rishav2416
#include <bits/stdc++.h>
#define ll long long
#define lli long long int
#define ld long double
#define mod 1000000000000000000
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(), x.end()
#define input(arr, n)                                                          \\
  for (ll c1 = 0; c1 < n; c1++)                                                \\
    cin >> arr[c1];
#define arrinit(arr, n, k)                                                     \\
  for (ll c1 = 0; c1 < n; c1++)                                                \\
    arr[i] = k;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define revrep(i, a, n) for (ll i = a; i >= n; i--)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define INF 1e18a

ll power(ll base, ll pow, ll mo) {
  ll res = 1;
  while (pow) {
    if (pow % 2 != 0)
      res = (res * base) % mo;
    base = (base * base) % mo;
    pow /= 2;
  }
  return res;
}

ll inv(ll i) { // mod must be prime and i must be coprime with mo
  return power(i, mod - 2, mod);
}

std::string str = "All Good Till Here";

/////////////////////////////////////////////////////////////////////////////////

void solve() {
  ll i, j, x, n;
  cin >> n;
  lli a[n];
  input(a, n);
  sort(a, a + n);
  lli p = 1;
  rep(i, 0, n) {
    if (a[i] == 0) {
      cout << 0 << '\\n';
      return;
    }
  }
  rep(i, 0, n) {
    if (a[i] > (mod / p)) {
      cout << -1 << "\\n";
      return;
    } else
      p *= a[i];
  }
  cout << p << "\\n";
  return;
}
int32_t main() {
  fastio ll tt;
  // cin>>tt;
  tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:

// written by: rishav2416
#include <bits/stdc++.h>
#define ll long long
#define lli long long int
#define ld long double
#define mod 1000000000000000000
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(), x.end()
#define input(arr, n)                                                          \\
  for (ll c1 = 0; c1 < n; c1++)                                                \\
    cin >> arr[c1];
#define arrinit(arr, n, k)                                                     \\
  for (ll c1 = 0; c1 < n; c1++)                                                \\
    arr[i] = k;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define revrep(i, a, n) for (ll i = a; i >= n; i--)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define INF 1e18a

ll power(ll base, ll pow, ll mo) {
  ll res = 1;
  while (pow) {
    if (pow % 2 != 0)
      res = (res * base) % mo;
    base = (base * base) % mo;
    pow /= 2;
  }
  return res;
}

ll inv(ll i) { // mod must be prime and i must be coprime with mo
  return power(i, mod - 2, mod);
}

std::string str = "All Good Till Here";

/////////////////////////////////////////////////////////////////////////////////

void solve() {
  ll i, j, x, n;
  cin >> n;
  lli a[n];
  input(a, n);
  sort(a, a + n);
  lli p = 1;
  rep(i, 0, n) {
    if (a[i] >= (mod / p)) {
      cout << -1 << "\\n";
      return;
    } else
      p *= a[i];
  }
  cout << p << "\\n";
  return;
}
int32_t main() {
  fastio ll tt;
  // cin>>tt;
  tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}