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

/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define vii vector<int>
#define vll vector<ll>
#define dt cout << "HERE\\n";
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpi vector<pll>
#define vpl vector<pll>
#define fi first
#define se second
#define sz size
#define len length

const ll inf = 1e18 + 1e17;
// const ll mod =1e9+7;
const ll mod = 998244353;

ll modInverse(ll a, ll m) {
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    ll q = a / m;
    ll t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}
ll powm(ll a, ll b) {
  a = a % mod;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res % mod);
}

const ll N = 2e5 + 5;

void solve() {
  int n;
  cin >> n;
  ll arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0) {
      cout << 0 << '\\n';
      return;
    }
  }
  ll ans = 1;
  ll lim = 1e18;
  for (int i = 0; i < n; i++) {
    if (lim / arr[i] < ans) {
      cout << -1 << '\\n';
      return;
    } else
      ans = ans * arr[i];
  }
  if (ans > 1e18) {
    cout << -1 << '\\n';
    return;
  }
  cout << ans << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //	#ifndef ONLINE_JUDGE
  //		freopen ("INPUT.txt" , "r" , stdin);
  //		freopen ("OUTPUT.txt", "w" , stdout);
  //	#endif

  int t = 1;

  // cin>>t;

  for (int i = 1; i <= t; i++) {
    // 	cout<<"Case #"<<i<<": ";
    solve();
  }
}

Error: -11

Fixed submission:

/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define vii vector<int>
#define vll vector<ll>
#define dt cout << "HERE\\n";
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpi vector<pll>
#define vpl vector<pll>
#define fi first
#define se second
#define sz size
#define len length

const ll inf = 1e18 + 1e17;
// const ll mod =1e9+7;
const ll mod = 998244353;

ll modInverse(ll a, ll m) {
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    ll q = a / m;
    ll t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}
ll powm(ll a, ll b) {
  a = a % mod;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res % mod);
}

const ll N = 2e5 + 5;

void solve() {
  int n;
  cin >> n;
  ll arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0) {
      cout << 0 << '\\n';
      return;
    }
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    if (1e18 / arr[i] < ans) {
      cout << -1 << '\\n';
      return;
    } else
      ans = ans * arr[i];
  }
  cout << ans << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //	#ifndef ONLINE_JUDGE
  //		freopen ("INPUT.txt" , "r" , stdin);
  //		freopen ("OUTPUT.txt", "w" , stdout);
  //	#endif

  int t = 1;

  cin >> t;

  for (int i = 1; i <= t; i++) {
    // 	cout<<"Case #"<<i<<": ";
    solve();
  }
}