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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  long long a, b, c, h, i, j, k, l, m, n, x, y;
  long long ans = 1;
  double aa, aans = 1.0;
  string s;
  cin >> n;
  // vector<ll>	aa(n);
  bool flag = true, zero = false;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (ans != 0) {
      c = 1000000000000000000ull / ans;
      if (c < a)
        flag = false;
    }
    ans *= a;
    aa = a;
    // aans *= aa;
    // if (aans > 1000000000000000000.0) flag = false;
    // if (ans > 1000000000000000000ull) flag = false;
    if (a == 0) {
      zero = true;
    }
  }

  if (flag == false && zero == false)
    ans = -1;

  // vector<ll>	dp(n+1,INFL);
  // vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  long long a, b, c, h, i, j, k, l, m, n, x, y;
  long long ans = 1;
  double aa, aans = 1.0;
  string s;
  cin >> n;
  // vector<ll>	aa(n);
  bool flag = true, zero = false;
  for (i = 0; i < n; i++) {
    cin >> a;
    c = 1000000000000000000ull / ans;
    if (c < a)
      flag = false;
    ans *= a;
    aa = a;
    // aans *= aa;
    // if (aans > 1000000000000000000.0) flag = false;
    // if (ans > 1000000000000000000ull) flag = false;
    if (a == 0) {
      zero = true;
    }
  }

  if (flag == false && zero == false)
    ans = -1;

  // vector<ll>	dp(n+1,INFL);
  // vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

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

#include <stdio.h>

int main() {
  const long long lim = 2000000000000000000ll;

  int N;
  scanf("%d", &N);
  long long A = 1;
  while (N--) {
    long long a;
    scanf("%lld", &a);
    if (a && A > lim / a)
      A = lim;
    else
      A *= a;
    if (A > lim)
      A = lim;
  }
  if (A > lim / 2)
    A = -1;
  printf("%lld\\n", A);
  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  const long long lim = 2000000000000000000ll;

  int N;
  scanf("%d", &N);
  long long A = 1;
  while (N--) {
    long long a;
    scanf("%lld", &a);
    if (A > lim / a)
      A = lim;
    else
      A *= a;
    if (A > lim)
      A = lim;
  }
  if (A > lim / 2)
    A = -1;
  printf("%lld\\n", A);
  return 0;
}
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++)

int main() {
  long long n, ans = 1;
  int flag = 0;
  cin >> n;

  rep(i, n) {
    long long a;
    cin >> a;
    if (a == 0 || ans == 0) {
      cout << 0;
      return 0;
    }
    long long tmp = 1000000000000000000 / a;
    if (ans > tmp) {
      flag = 1;
    }
    if (flag == 0)
      ans *= a;
  }

  if (flag == 1)
    cout << -1;
  else
    cout << ans;
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  long long n, ans = 1;
  int flag = 0;
  cin >> n;
  rep(i, n) {
    long long a;
    cin >> a;
    if (a == 0 || ans == 0) {
      cout << 0;
      return 0;
    }
    if (a > (long long)1000000000000000000 / ans) {
      flag = 1;
    }
    ans *= a;
  }

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;

#define FOR(i, a, b) for (int i = a; i < (b); i++)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

#define trav(container, it)                                                    \\
  for (typeof(container.begin()) it = container.begin();                       \\
       it != container.end(); it++)

const int MOD = 1000000007;
const char nl = '\\n';

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vl v(n);
  FOR(i, 0, n) cin >> v[i];

  ll res = 1;
  sort(all(v));
  if (v[0] == 0)
    res = 0;
  else
    FOR(i, 0, n) {
      if (v[i] > 1000000000000000000 / res) {
        res = -1;
        break;
      } else
        res *= v[i];
    }

  cout << res << nl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;

#define FOR(i, a, b) for (int i = a; i < (b); i++)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

#define trav(container, it)                                                    \\
  for (typeof(container.begin()) it = container.begin();                       \\
       it != container.end(); it++)

const int MOD = 1000000007;
const char nl = '\\n';

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vl v(n);
  FOR(i, 0, n) cin >> v[i];

  ll res = 1;
  sort(all(v));
  if (v[0] == 0)
    res = 0;
  else
    FOR(i, 0, n) {
      res *= v[i];
      if (v[i] < 1000000000000000000 / res) {
        res = -1;
        break;
      }
    }

  cout << res << nl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for (auto &x : a)
    cin >> x;
  sort(a.begin(), a.end());

  long seki = 1;
  for (long x : a) {
    if (x > 0 && seki > long(1e18) / x) {
      return cout << -1 << endl, 0;
    }
    seki *= x;
  }
  cout << seki << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a)
    cin >> x;
  sort(a.begin(), a.end());

  long seki = 1;
  for (int i = 0; i < n; i++) {
    long x = a[i];
    if ((long)1e18 / x > x) {
      return cout << -1 << endl, 0;
    }
    seki *= x;
  }
  cout << seki << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  setprecision(20);

  int n;
  cin >> n;

  int dig = 0;
  int ans = 1;
  int a[n];
  bool f = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      f = 1;
    }
  }
  sort(a, a + n);
  int maxi = 1e18;
  if (f) {
    cout << 0;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (ans > maxi / a[i]) {
      cout << -1;
      return 0;
    }
    ans = ans * a[i];
  }
  cout << ans;
}

Error: WA

Fixed submission:

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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  setprecision(20);

  int n;
  cin >> n;

  int dig = 0;
  int ans = 1;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int maxi = 1e18;
  bool f = 0;

  for (int i = 0; i < n; i++) {
    if (ans > maxi / a[i]) {
      cout << -1;
      return 0;
    }
    ans = ans * a[i];
  }
  cout << ans;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  Bint A;
  cin >> A;
  Bint N = 1;
  Bint B;
  int c = 0;
  for (int i = 0; i < A; i++) {
    cin >> B;
    if (c != 0 && B != 0) {
      if (i == A - 1) {
        N = -1;
        break;
      } else {
        continue;
      }
    } else if (B == 0) {
      N = 0;
      break;
    }
    N = N * B;
    if (N > 1000000000000000000) {
      c++;
      if (i == A - 1) {
        N = -1;
      }
    }
  }
  cout << N << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define int long long
int INF = 1e18;
signed main() {
  int N; // 60
  cin >> N;
  vector<int> A(N);
  vector<int> cnt;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (A[i] != 1) {
      cnt.push_back(A[i]);
    }
  }
  if (cnt.size() > 60LL) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 1;
  for (int i = 0; i < 60LL; i++) {
    ans *= cnt[i];
    if (ans > INF) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
// const ll LLMAX = LLONG_MAX;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll answer = 1;

  // a.sort(a.begin(), a.end());
  rep(i, n) {
    if (a[i] > INF / answer) {
      answer = INF + 1;
    } else
      answer *= a[i];
  }
  if (answer > INF)
    cout << -1 << endl;
  else
    cout << answer << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
// const ll LLMAX = LLONG_MAX;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll answer = 1;

  // a.sort(a.begin(), a.end());
  rep(i, n) {
    if (a[i] > INF / answer) {
      answer = INF + 1;
    } else
      answer *= a[i];
  }
  if (answer > INF)
    cout << -1 << endl;
  else
    cout << answer << endl;

  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

using ll = long long;
using ull = unsigned long long;
constexpr ll N = 2e5;

constexpr ull max_num = 1e18;
ull a[N];

int main() {

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }

  Bint sum = a[0];
  bool f = false;
  for (int i = 1; i < n; i++) {
    sum *= a[i];

    if (sum > max_num) {
      for (int j = i + 1; j < n; j++) {
        if (a[j] == 0) {
          sum = 0;
          goto r;
        }
      }
      f = true;
      break;
    }
  }

r:
  if (f)
    cout << "-1" << endl;
  else
    cout << sum << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

using ll = long long;
using ull = unsigned long long;
constexpr ll N = 2e5;

constexpr ull max_num = 1e18;
ull a[N];

int main() {

  // while (true) {

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }

  Bint sum = a[0];
  for (int i = 1; i < n; i++) {
    sum *= a[i];
  }
  if (sum > max_num)
    cout << "-1" << endl;
  else
    cout << sum << endl;

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

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (i = a; i < b; i++)
#define per(i, a, b) for (i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define trav(x, it) for (auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x, y) memset(x, y, sizeof(x))
#define endl "\\n"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
double eps = 1e-7;
ll mod = 1000000007;
ll N = 998244353;

ll binpow(ll b, ll p) {
  ll ans = 1;
  while (p > 0) {
    if (p & 1)
      ans = (ans * b) % mod;
    b = (b * b) % mod;
    p >>= 1;
  }
  return ans;
}
ll modinv(ll x) { return binpow(x, mod - 2); }

void solve() {
  ll n, i, a;
  cin >> n;
  ll arr[n];
  ll ans = 1;
  int f = 0;
  rep(i, 0, n) {
    cin >> arr[i];
    if (arr[i] == 0)
      f = 1;
  }
  if (f) {
    cout << 0 << endl;
    return;
  }
  rep(i, 0, n) {
    if (arr[i] <= ((ll)1e18 / ans))
      ans *= arr[i];
    else {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (i = a; i < b; i++)
#define per(i, a, b) for (i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define trav(x, it) for (auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x, y) memset(x, y, sizeof(x))
#define endl "\\n"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
double eps = 1e-7;
ll mod = 1000000007;
ll N = 998244353;

ll binpow(ll b, ll p) {
  ll ans = 1;
  while (p > 0) {
    if (p & 1)
      ans = (ans * b) % mod;
    b = (b * b) % mod;
    p >>= 1;
  }
  return ans;
}
ll modinv(ll x) { return binpow(x, mod - 2); }

void solve() {
  ll n, i, a;
  cin >> n;
  vi arr;
  ll ans = 1;
  rep(i, 0, n) {
    cin >> a;
    arr.eb(a);
  }
  if (count(all(arr), 0)) {
    cout << 0 << endl;
    return;
  }
  rep(i, 0, n) {
    if (arr[i] <= ((ll)1e18 / ans))
      ans *= arr[i];
    else {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

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

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

#include <bits/stdc++.h>
using namespace std;
// Author: Ezio Sam
/* Shorthands */
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second
#define po(x) x *x
/* STL */
#define vi vector<int> v
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mem(a, n) memset(a, n, sizeof(a));
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mx(v) *max_element(v.begin(), v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(), a.end())
/* loops */
#define fr(i, n) for (__typeof(n) i = 0; i < (n); i++)
#define fn(i, n) for (__typeof(n) i = 1; i <= (n); i++)
#define fa(i, a, n) for (__typeof(a) i = (a); i <= (b); i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define db(something) cerr << #something << " - " << something << "\\n";
int main() {

  Ezio
      /*Variables*/
      /*Code*/
      ll n,
      x;
  vector<ll> v;
  ll ans = 1;
  const ll m = 1e18;
  int i;
  cin >> n;

  fr(i, n) {
    cin >> x;
    if (x == 0) {
      cout << 0;
      return 0;
    }
    v.pb(x);
  }

  sort(all(v));

  fr(i, n) {
    if (ans <= m / v[i])
      ans *= v[i];

    else {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// Author: Ezio Sam
/* Shorthands */
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second
#define po(x) x *x
/* STL */
#define vi vector<int> v
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mem(a, n) memset(a, n, sizeof(a));
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mx(v) *max_element(v.begin(), v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(), a.end())
/* loops */
#define fr(i, n) for (__typeof(n) i = 0; i < (n); i++)
#define fn(i, n) for (__typeof(n) i = 1; i <= (n); i++)
#define fa(i, a, n) for (__typeof(a) i = (a); i <= (b); i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define db(something) cerr << #something << " - " << something << "\\n";
int main() {

  Ezio
      /*Variables*/
      /*Code*/
      ll n,
      x;
  vector<ll> v;
  ll ans = 1;
  const ll m = 1e18;
  int i;
  cin >> n;

  fr(i, n) {
    cin >> x;
    v.pb(x);
  }

  sort(all(v));

  fr(i, n) {
    if (ans <= m / v[i])
      ans *= v[i];

    else {
      cout << "-1" << endl;
      return 0;
    }
  }

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

#include <iostream>
using namespace std;

int main() {
  int n;
  long long ans = 1, f = 0;
  cin >> n;
  for (int i = 0; n > i; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    // cout << ans << endl;
    if (ans > 1000000000000000000LL / a) {
      f = 1;
    }
    ans = ans * a;
  }
  if (f)
    ans = -1;
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  long long ans = 1, f = 0;
  cin >> n;
  for (int i = 0; n > i; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    cout << ans << endl;
    if (a > 1000000000000000000LL / ans) {
      f = 1;
    }
    ans = ans * a;
  }
  if (f)
    ans = -1;
  cout << ans << 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;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  ll check = 1e18;
  ll sum = 1;
  bool zero = false;
  bool big = false;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      zero = true;
    }

    if (big ||
        check / sum <
            a) { // ここの条件の移項でミスしていたのか！[sum*a>check]を[a>check/sum]で判別すれば桁もれず
      big = true;
    }
    sum *= a;
  }
  if (zero) {
    cout << 0 << endl;
  } else if (big) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll check = 1e18;
  ll sum = 1;
  bool zero = 0;
  bool big = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a >
        check /
            sum) { // ここの条件の移項でミスしていたのか！[sum*a>check]を[a>check/sum]で判別すれば桁もれず
      big = 1;
    }
    sum *= a;
    if (a == 0) {
      zero = 1;
    }
    if (sum > check) {
      big = 1;
      sum = 0;
    }
  }
  if (zero) {
    cout << 0 << endl;
  } else if (big) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error


#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long int> aa(n);
  long long a = 1;
  for (size_t i = 0; i < n; i++) {
    cin >> aa[i];
    if (aa[i] == 0) {
      a = 0;
    }
  }
  int tf = 1;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (size_t i = 0; i < n; i++) {
      if (1000000000000000000 / a >= aa[i]) {
        a *= aa[i];
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << a << endl;
  return 0;
}

Error: 0

Fixed submission:


#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long int> aa(n);
  long long a = 1;
  for (size_t i = 0; i < n; i++) {
    cin >> aa[i];
    if (aa[i] == 0) {
      a = 0;
    }
  }
  int tf = 1;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (size_t i = 0; i < n; i++) {
      if (1000000000000000000 / a < aa[i]) {
        tf = 0;
      }
      a *= aa[i];
    }
  }
  if (tf) {
    cout << a << 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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;

int main() {
  int n;
  cin >> n;
  ll pro = 1;
  bool boo = false;
  for (int i = 0; i < n; i++) {
    ll proo = pro;
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (pro > 1000000000000000000 / a) {
      boo = true;
    }
    pro *= a;
  }
  if (boo) {
    cout << -1 << endl;
    return 0;
  }
  if (pro > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << pro << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll pro = 1;
  bool boo = false;
  for (int i = 0; i < n; i++) {
    ll proo = pro;
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
    }
    if (pro > 1000000000000000000 / a) {
      boo = true;
    }
    pro *= a;
  }
  if (boo) {
    cout << -1 << endl;
    return 0;
  }
  if (pro > 1000000000000000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << pro << endl;
}