alexjercan/bugnet huggingface dataset:
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;

const ll MX = 1e18;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll b = 1;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  rep(j, n) {
    if (a[j] <= 1000000000000000000 / b) {
      b *= a[j];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << b << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
  int N;
  vector<int> A(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int ans = A.at(0);
  for (int i = 1; i < N; i++) {
    ans *= A.at(i);
  }
  if (ans >= 1000000000000000001)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

const long double Pi = acos(-1), e = 2.718;
const ll N = 1e18, mod = 1e9 + 7;

int main() {
  FASTIO;
  ll n;
  cin >> n;
  ll sum = 1;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(all(a));
  if (a[0] == 0)
    return cout << 0 << endl, 0;
  for (auto x : a) {
    if (x > N / sum)
      return cout << -1 << endl, 0;
    sum *= x;
  }
  cout << sum << endl;
  return 0;
}
/**


*/


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

const long double Pi = acos(-1), e = 2.718;
const ll N = 1e18, mod = 1e9 + 7;

int main() {
  FASTIO;
  ll n;
  cin >> n;
  ll sum = 1;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(all(a));
  for (auto x : a) {
    if (x > N / sum)
      return cout << -1 << endl, 0;
    sum *= x;
  }
  cout << sum << endl;
  return 0;
}
/**


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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

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

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

int main() {

  int N;
  cin >> N;
  ll ans = 1;
  REP(i, N) {
    ll a;
    cin >> a;
    if (1000000000000000000 / ans < a) {
      ans = -1;
    } else {
      ans *= a;
    }
    if (a == 0) {
      ans = 0;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

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

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

int main() {

  int N;
  cin >> N;

  long long ans = 1;
  bool over = false;
  int sign = 1;
  REP(i, N) {
    long long a;
    cin >> a;
    if (1000000000000000000 / ans < std::abs(a)) {
      over = true;
    }
    if (!over) {
      ans *= std::abs(a);
    }
    if (a < 0) {
      sign *= -1;
    }
    if (a == 0) {
      ans *= 0;
    }
  }
  if (over && ans != 0 && sign > 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans * sign << endl;

  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define int unsigned long long
using namespace std;
int a[100005];
long double s = 1;
signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    s *= a[i];
    if (s > 1000000000000000000) {
      cout << -1;
      return 0;
    }
  }
  cout << (long long)s;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define int unsigned long long
using namespace std;
int a[10005], sum;
signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0;
      return 0;
    }
    sum += log10(a[i]);
  }
  if (sum > 19) {
    cout << -1;
    return 0;
  }
  sort(a + 1, a + n + 1);
  int s = a[1];
  for (int i = n; i >= 2; i--) {
    s *= a[i];
    if (s > 1000000000000000000) {
      cout << -1;
      return 0;
    }
  }
  cout << s;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll i : A) {
    if (i != 0 && ans > m / i) {
      ans = -1;
      break;
    }
    ans *= i;
  }
  print(ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll i : A) {
    if (ans > m / i) {
      ans = -1;
      break;
    }
    ans *= i;
  }
  print(ans);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll a : A) {
    if (a > 0 && ans > m / a) {
      ans = -1;
      break;
    }
    ans *= a;
  }
  print(ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 1, m = 1e18;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  sort(ALL(A));
  for (ll a : A) {
    if (ans > m / a) {
      ans = -1;
      break;
    }
    ans *= a;
  }
  print(ans);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  typedef unsigned long long _ull;
  const _ull LIM = 1000000000000000000ULL;
  int N;

  cin >> N;
  vector<_ull> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  _ull mul = 1ULL;

  for (int i = 0; i < N; i++) {
    if (LIM / A.at(i) < mul) {
      cout << -1 << endl;
      return 0;
    }
    mul *= A.at(i);
    if (mul > LIM) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << mul << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  vector<long long int> A(N);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long int mul = 1;
  for (int i = 0; i < N; i++) {
    if (log10(mul) + log10(A[i]) > 18.0) {
      cout << -1 << endl;
      return 0;
    }

    mul *= A[i];
    if (mul > 1e10) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << mul << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  ll st = 1;
  ll lim = 1000000000000000000ll;
  ll A[N];
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  rep(i, N) {
    ll a;
    a = A[i];
    if (a == 0) {
      st = 0;
      continue;
    }
    if (st > lim / a) {
      cout << -1 << endl;
      return 0;
    }
    st *= a;
  }
  cout << st << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  ll st = 1;
  ll lim = 1000000000000000000ll;
  ll A[N];
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  rep(i, N) {
    ll a;
    a = A[i];
    if (st > lim / a) {
      cout << -1 << endl;
      return 0;
    }
    st *= a;
  }
  cout << st << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for (long long i = 0; i < n; i++)

template <class T> inline void chmax(T &ans, T t) {
  if (t > ans)
    ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
  if (t < ans)
    ans = t;
}

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);

  ll now = 1;
  ll t = 1000000000000000000LL;
  Bint total = 1;
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  rep(i, n) {
    total *= a[i];
    if (total > t) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (total > t) {
    cout << -1 << endl;
  } else {
    cout << total << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;

#define rep(i, n) for (long long i = 0; i < n; i++)

namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);

  ll now = 1;
  ll t = 1000000000000000000LL;
  Bint total = 1;
  rep(i, n) {
    cin >> a[i];
    total *= a[i];
  }

  if (total > t) {
    cout << -1 << endl;
  } else {
    cout << total << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

// sppsfver - 05.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

ll n, a, ans = 1;
bool flag, zero;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0)
      return cout << 0 << endl, 0;
    a <= (ll)(1e18) / ans ? ans *= a : flag = 1;
  }
  cout << (flag ? -1 : ans) << endl;
  return 0;
}


Error: WA

Fixed submission:

// sppsfver - 05.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

ll n, a, ans = 1;
bool flag, zero;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0)
      return cout << 0 << endl, 0;
    flag |= (a <= (ll)(1e18) / ans);
    ans *= a;
  }
  cout << (flag ? -1 : ans) << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using namespace boost::multiprecision;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1e18 + 1LL;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
  ll n;
  cin >> n;

  cpp_int ans = 1;
  bool zero = false;
  vector<cpp_int> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      zero = true;
    }
  }

  if (zero) {
    out(0);
    re0;
  }

  rep(i, n) {
    ans *= a[i];
    if (ans > 1000000000000000000) {
      out(-1);
      re0;
    }
  }

  out(ans);
  re0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using namespace boost::multiprecision;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1e18 + 1LL;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
  ll n;
  cin >> n;

  cpp_int ans = 1;
  bool zero = false;
  rep(i, n) {
    cpp_int a;
    cin >> a;
    if (a == 0) {
      zero = true;
    }
    ans *= a;
  }

  if (zero) {
    out(0);
    re0;
  }

  if (ans > 1000000000000000000) {
    out(-1);
  } else {
    out(ans);
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define ALL(v) (v).begin(), (v).end()
#define INF 1000000000000000000

int main() {
  unsigned long long N;
  cin >> N;
  vector<unsigned long long> a(N);
  cin >> a[0];
  unsigned long long ans = a[0];
  rep(i, 1, N) {
    cin >> a[i];
    if (ans != 0)
      if (a[i] > INF / ans)
        ans = INF + 2;
      else {
        ans *= a[i];
        if (ans > INF)
          ans = INF + 2;
      }
  }

  if (ans <= INF)
    cout << ans << endl;
  else if (ans > INF)
    cout << -1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define ALL(v) (v).begin(), (v).end()
#define INF 1000000000000000000

int main() {
  unsigned long long N;
  cin >> N;
  vector<unsigned long long> a(N);
  cin >> a[0];
  unsigned long long ans = a[0];
  rep(i, 1, N) {
    cin >> a[i];
    if (a[i] > INF / ans)
      ans = INF + 2;
    else {
      ans *= a[i];
      if (ans > INF)
        ans = INF + 2;
    }
  }

  if (ans <= INF)
    cout << ans << endl;
  else if (ans > INF)
    cout << -1 << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sz(a) signed(a.size())
using namespace std;

void solve() {
  ll n, i;
  cin >> n;
  ll m = 1e18;
  ll prod = 1;
  bool flag = 0, z = 0;
  for (i = 1; i <= n; i++) {
    ll a;
    cin >> a;
    z += (a == 0);
    if (a && prod > m / a) {
      // cout << i << " ";
      flag = 1;
    }
    prod *= a;
  }
  if (z)
    cout << 0;
  else if (!flag)
    cout << prod;
  else
    cout << -1;
}

int main() {
  FAST;
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sz(a) signed(a.size())
using namespace std;

void solve() {
  ll n, i;
  cin >> n;
  ll m = 1e18;
  ll prod = 1;
  bool flag = 0;
  for (i = 1; i <= n; i++) {
    ll a;
    cin >> a;
    if (a > m / prod) {
      cout << -1;
      flag = 1;
    }
    prod *= a;
  }
  if (!flag)
    cout << prod;
}

int main() {
  FAST;
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  ll sum = 1;
  vector<ll> vec(N);
  rep(i, N) { cin >> vec.at(i); }
  sort(vec.begin(), vec.end());
  if (vec.at(0) == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    rep(i, N) {
      if (sum >= (1000000000000000000 / vec.at(i)) + 1) {
        cout << -1 << endl;
        return 0;
      } else {
        sum = sum * vec.at(i);
      }
    }
    cout << sum << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  ll N = 1;
  for (int i = 0; i < n; i++) {
    N = N * vec.at(i);
    if (N > 1000000000000000000 / vec.at(i) + 1) {
      break;
    }
  }
  if (N <= 1000000000000000000 && N >= 0) {
    cout << N << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxi = 1e18;

int main() {
  int n;
  cin >> n;
  bool zero = false;
  ll ar[n];
  for (int i = 0; i < n; i++) {
    ll cur;
    cin >> ar[i];
    if (ar[i] == 0)
      zero = true;
  }
  if (zero) {
    cout << 0 << '\\n';
  } else {
    ll sol = 1;
    bool ex = false;
    for (int i = 0; i < n; i++) {
      if (ar[i] > maxi / sol) {
        cout << -1 << '\\n';
        ex = true;
        break;
      } else {
        sol *= ar[i];
      }
    }
    if (!ex)
      cout << sol << '\\n';
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxi = 1e18;

int main() {
  int n;
  cin >> n;
  ll sol = 1;
  bool zero = false;
  bool exed = false;
  for (int i = 0; i < n; i++) {
    ll cur;
    cin >> cur;
    if (cur == 0)
      zero = true;
    if (cur > maxi / sol)
      exed = false;
    else
      sol *= cur;
  }
  if (zero) {
    cout << 0 << '\\n';
  } else {
    if (exed)
      cout << -1 << '\\n';
    else
      cout << sol << '\\n';
  }
}