alexjercan/bugnet huggingface dataset:
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
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: TLE

Fixed submission:

#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;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main() {
  Bint A;
  cin >> A;
  Bint N = 1;
  Bint B;
  for (int i = 0; i < A; i++) {
    cin >> B;
    N = N * B;
    if (i == A - 1 && N > 1000000000000000000) {
      N = -1;
      break;
    }
  }

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

#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if (0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T> vector<T> read_n(ll n) {
  vector<T> ret(n);
  for (ll i = 0; i < n; i++)
    cin >> ret[i];
  return ret;
}

template <typename iter> void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin)
      cout << " ";
    cout << *it;
  }
  cout << endl;
}

const ll top = 1e18;

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

  ll ret = 1;
  ll n;
  cin >> n;

  int fail = 0;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;

    if (ret != 0 && top / ret < x) {
      fail = 1;
    }

    if (x == 0) {
      fail = 0;
    }

    ret *= x;
  }

  if (fail) {
    cout << "-1\\n";
  } else {
    cout << ret << "\\n";
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if (0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T> vector<T> read_n(ll n) {
  vector<T> ret(n);
  for (ll i = 0; i < n; i++)
    cin >> ret[i];
  return ret;
}

template <typename iter> void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin)
      cout << " ";
    cout << *it;
  }
  cout << endl;
}

const ll top = 1e18;

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

  ll ret = 1;
  ll n;
  cin >> n;

  int fail = 0;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;

    if (top / ret < x) {
      fail = 1;
    }

    if (x == 0) {
      fail = 0;
    }

    ret *= x;
  }

  if (fail) {
    cout << "-1\\n";
  } else {
    cout << ret << "\\n";
  }

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename Tu>
static inline constexpr bool is_multiplication_safe(Tu a, Tu b) {
  return !a || b <= numeric_limits<Tu>::max() / a;
}

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

  ll ans = 1, a = 0;
  int n;
  bool over = false, zero = false;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a == 0) {
      zero = true;
      break;
    }
    if (!over) {
      if (ans * a > 1000000000000000000ll || !is_multiplication_safe(ans, a))
        over = true;
      ans *= a;
    }
  }

  if (zero)
    printf("0\\n");
  else if (over)
    printf("-1\\n");
  else
    printf("%lld\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename Tu>
static inline constexpr bool is_multiplication_safe(Tu a, Tu b) {
  return !a || b <= numeric_limits<Tu>::max() / a;
}

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

  ll ans = 1, a = 0;
  int n;
  bool over = false, zero = false;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a == 0) {
      zero = true;
      break;
    }
    if (ans * a > 1000000000000000000ll || !is_multiplication_safe(ans, a))
      over = true;
    ans *= a;
  }

  if (zero)
    printf("0\\n");
  else if (over)
    printf("-1\\n");
  else
    printf("%lld\\n", ans);

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int

int main() {
  ull N, ans = 1;
  cin >> N;
  std::vector<ull> A(N);

  for (ull i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      ans = 0;
      break;
    }
  }

  if (ans != 0) {
    for (ull i = 0; i < N; i++) {
      if (A[i] > 1000000000000000000 / ans) {
        ans = -1;
        break;
      }
      ans *= A[i];
    }
  }

  cout << (ll)ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int

int main() {
  ull A, N, p = 0, ans = 1;
  cin >> N;

  for (ull i = 0; i < N; i++) {
    cin >> A;
    if (A == 0) {
      p = 2;
      break;
    }
    if (A > 1000000000000000000 / ans) {
      p = 1;
    }
    ans *= A;
  }

  if (p == 1) {
    cout << -1 << endl;
  } else if (p == 2) {
    cout << 0 << endl;
  } else {
    cout << (ll)ans << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define mod 1e18 + 1
typedef long long ll;
int main() {
  ll n, total = 1, ans = 1, zero = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (x == 0 || zero) {
      zero++;
      continue;
    }
    if (x <= 1000000000000000000 / total) {
      total *= x;
    } else
      ans = -1;
  }
  if (zero)
    cout << 0;

  else if (ans == -1)
    cout << -1;
  else
    cout << total;
  cout << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1e18 + 1
typedef long long ll;
int main() {
  ll n, total = 1, ans = 1, zero = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (x == 0)
      zero++;
    if (x <= 1000000000000000000 / total) {
      total *= x;
    } else
      ans = -1;
  }
  if (ans == -1)
    cout << -1;
  else if (zero)
    cout << 0;
  else
    cout << total;
  cout << "\\n";
  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)
#define ll long long
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);

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

  sort(a.begin(), a.end());
  ll ans = 1;
  rep(i, n) {
    if (a[i] == 0) {
      ans = 0;
      break;
    }
    if (ans > INF / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);

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

  sort(a.begin(), a.end());
  ll ans = 1;
  rep(i, n) {
    if (a[i] == 0)
      ans = 0;
    if (ans > INF / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define watch(x)                                                               \\
  ;                                                                            \\
  cout << "\\n" << #x << " is: " << x << "\\n";
#define ll long long int
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define pb push_back
#define nl cout << "\\n"
#define gcd(a, b) __gcd(a, b)
#define sq(a) (a) * (a)
#define loop(i, a, b) for (int i = a; i <= b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
#define sz(a) a.size()
#define mod 1000000007
#define PI 2 * acos(0.0)

int main() {
  IOS int T = 1;
  // cin>>T;
  while (T--) {
    ll n, q = 1, p = 1;
    cin >> n;
    ll a[n];
    loop(i, 0, n - 1) {
      cin >> a[i];
      if (a[i] == 0) {
        q = 0;
        cout << 0;
        break;
      }
    }
    if (q == 0)
      continue;
    loop(i, 0, n - 1) {
      if (a[i] > 1000000000000000000 / p) {
        q = 0;
        break;
      } else
        p *= a[i];
    }
    if (q or p == 0)
      cout << p;
    else
      cout << -1;
  }
  return 0;
}


Error: WA

Fixed submission:

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define watch(x)                                                               \\
  ;                                                                            \\
  cout << "\\n" << #x << " is: " << x << "\\n";
#define ll long long int
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define pb push_back
#define nl cout << "\\n"
#define gcd(a, b) __gcd(a, b)
#define sq(a) (a) * (a)
#define loop(i, a, b) for (int i = a; i <= b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
#define sz(a) a.size()
#define mod 1000000007
#define PI 2 * acos(0.0)

int main() {
  IOS int T = 1;
  // cin>>T;
  while (T--) {
    ll n, q = 1, p = 1;
    cin >> n;
    ll a[n];
    loop(i, 0, n - 1) {
      cin >> a[i];
      if (a[i] == 0) {
        q = 0;
        cout << 0;
        break;
      }
    }
    if (q == 0)
      continue;
    loop(i, 0, n - 1) {
      p *= a[i];
      if (a[i] <= 1000000000000000000 / p) {
        q = 0;
        break;
      }
    }
    if (q or p == 0)
      cout << p;
    else
      cout << -1;
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

#define FAST_INP                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
int main() {
  FAST_INP;
  int n;
  long long a, ans = 1, m = (long long)1e18;
  cin >> n;
  bool f = false;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      ans = 0;
      f = false;
      break;
    }
    if (!f) {
      if (m / ans < a) {
        f = true;
      }
      ans *= a;
    }
  }
  if (f)
    ans = -1;

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

Error: WA

Fixed submission:

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

#define FAST_INP                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
int main() {
  FAST_INP;
  int n;
  long long a, ans = 1;
  cin >> n;
  bool f = false;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      ans = 0;
      f = false;
      break;
    }
    ans *= a;
    if (1000000000000000000 / ans < a) {
      f = true;
    }
  }
  if (f)
    ans = -1;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
const ll mod = 1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0; // 角度转弧度
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const int N = 1e5 + 10;

ll a;
int main() {
  int n;
  cin >> n;
  ll tmp = 1e18;
  ll ans = 1;
  rep(i, 0, n) {
    scanf("%lld", &a);
    if (a == 0) {
      ans = 0;
      continue;
    }
    tmp = tmp / a; // cout<<tmp<<"\\n";
    if (tmp != 0)
      ans *= a;
  }
  // cout<<99999900000 / 999999000001<<"\\n";
  if (tmp == 0 && ans != 0) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
const ll mod = 1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0; // 角度转弧度
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const int N = 1e5 + 10;

ll a;
int main() {
  int n;
  cin >> n;
  ll tmp = 1e18;
  ll ans = 1;
  rep(i, 0, n) {
    scanf("%lld", &a);
    tmp = tmp / a; // cout<<tmp<<"\\n";
    ans *= a;
  }
  // cout<<99999900000 / 999999000001<<"\\n";
  if (tmp == 0) {
    cout << -1;
  } else {
    cout << ans;
  }
  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 < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  constexpr ll max = 1e18;
  ll ans = 1;
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      puts("0");
      return 0;
    }
  }
  rep(i, n) {
    if (a.at(i) > max / ans) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= a.at(i);
    }
  }
  cout << ans << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a;
  ll max = 1000000000000000000;
  ll ans = 1;
  rep(i, n) { cin >> a.at(i); }
  rep(i, n) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
      break;
    }
    if (a.at(i) > max / ans) {
      cout << -1 << endl;
      break;
    } else {
      ans *= a.at(i);
    }
  }
  cout << ans << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

inline int ctoi(char c) {
  if (c < '0' || '9' < c)
    throw invalid_argument("ctoi error");
  return c - '0';
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T> inline T gcd(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("gcd error: x <= 0 or y <= 0");

  if (x < y)
    swap(x, y);
  T r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}
template <typename T> inline T lcm(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("lcm error: x <= 0 or y <= 0");

  return x * y / gcd(x, y);
}

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

  vector<unsigned long long int> input;

  rep(i, n) {
    unsigned long long int a;
    cin >> a;

    if (a == 0) {
      cout << 0;
      return 0;
    }

    input.push_back(a);
  }

  unsigned long long ans = input[0];

  REP(i, 1, input.size()) {
    if (18 <= log10(ans) + log10(input[i])) {
      if (1000000000000000000 / ans == input[i]) {
        ans = 1000000000000000000;
      } else {
        cout << -1;
        return 0;
      }
    } else {
      ans *= input[i];
    }
  }

  cout << ans;

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

inline int ctoi(char c) {
  if (c < '0' || '9' < c)
    throw invalid_argument("ctoi error");
  return c - '0';
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T> inline T gcd(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("gcd error: x <= 0 or y <= 0");

  if (x < y)
    swap(x, y);
  T r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}
template <typename T> inline T lcm(T x, T y) {
  if (x <= 0 || y <= 0)
    throw invalid_argument("lcm error: x <= 0 or y <= 0");

  return x * y / gcd(x, y);
}

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

  vector<unsigned long long int> input;

  rep(i, n) {
    unsigned long long int a;
    cin >> a;

    if (a == 0) {
      cout << 0;
      return 0;
    }
  }

  unsigned long long ans = input[0];

  REP(i, 1, input.size()) {
    if (18 <= log10(ans) + log10(input[i])) {
      if (1000000000000000000 / ans == input[i]) {
        ans = 1000000000000000000;
      } else {
        cout << -1;
        return 0;
      }
    } else {
      ans *= input[i];
    }
  }

  cout << ans;

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

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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  unsigned long long s = 1;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (1000000000000000000 / s < a.at(i)) {
      cout << -1 << endl;
      return 0;
    }

    s *= a.at(i);
  }
  cout << s << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  unsigned long long s = 1;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
    }

    if (1000000000000000000 / s < a.at(i)) {
      cout << -1 << endl;
      return 0;
    }

    s *= a.at(i);
  }
  cout << s << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, i, flag = 1, cnt = 0;
  cin >> n;

  unsigned long long int ar[n], pro = 1, k = 1000000000000000000;

  for (i = 0; i < n; i++) {
    cin >> ar[i];

    if (ar[i] == 0)
      cnt++;
  }

  if (cnt == 0) {
    for (i = 0; i < n; i++) {
      if (ar[i] <= (k / pro)) // this is same as pro>10^18
      {
        pro = (pro * ar[i]);
      } else {
        cout << "-1";
        return 0;
      }
    }
  } else {
    cout << "0";
    return 0;
  }

  cout << pro;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, flag = 1, cnt = 0;
  cin >> n;

  unsigned long long int ar[n], pro = 1, k = 1000000000000000000;

  for (i = 0; i < n; i++) {
    cin >> ar[i];

    if (ar[i] == 0)
      cnt++;
  }

  if (cnt == 0) {
    for (i = 0; i < n; i++) {
      pro = (pro * ar[i]);

      if (ar[i] < k / pro) // this is same as pro>10^18
      {
        flag = 0;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 2e5 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, a[N];
  ll c = 1e18;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > c) {
      cout << -1;
      return 0;
    }
    c = c / a[i];
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans = ans * a[i];
  }
  cout << ans << '\\n';
}


Error: WA

Fixed submission:


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
ll c = 1e18;
int main() {
  ll n, x, ans = 1;
  vector<ll> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (x > 1) {
      v.push_back(x);
    }
  }
  if ((int)v.size() >= 60) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    ans = ans * v[i];
    if (ans >= c) {
      cout << -1;
      return 0;
    }
  }
  cout << ans << '\\n';

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

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

int main() {
  int n, flag = 0;
  long long k = 1;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i] && k > 1000000000000000000 / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    k *= a[i];
  }
  cout << k;
}

Error: WA

Fixed submission:

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

int main() {
  int n, flag = 0;
  long long k = 1;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] > 1000000000000000000 / k)
      flag = 1;
    k *= a[i];
  }
  if (flag)
    cout << -1;
  else
    cout << k;
}
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>;

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  ll ans = 1;

  // ソートしとくと0判定が楽
  sort(a.begin(), a.end());
  // rep(i,n) cout<<a.at(i)<<endl;

  rep(i, n) {
    // aの要素に0があったら即座に0出力して終わり．
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
    // 1e18を超えたら-1を出力して終わり．
    if (MX / ans >= a.at(i)) { // この条件だと次a(i)を数かける前に終われる．
      ans *= a.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: WA

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>;

const ll MX = 1e18;

int main() {
  int n;
  vector<ll> a(11000);
  cin >> n;
  rep(i, n) cin >> a.at(i);
  ll ans = 1;

  rep(i, n) {
    if ((MX + 1) / ans <= a.at(i)) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a.at(i);
  }
  cout << ans << endl;

  // rep(i,n) cin >> a.at(i);
  // rep(i,n) {
  //     if(a.at(i)==0){
  //         cout<<0<<endl;
  //         return 0;
  //     }
  // }
  // ll ans=1;
  // rep(i,n){
  //     ans *= a.at(i);
  //     if(ans>(ll)pow(10,18)){
  //         cout<<-1<<endl;
  //         return 0;
  //     }
  // }
  // cout<<ans<<endl;
  return 0;
}