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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

const ll D = pow(10, 18);

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

  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  sort(all(A));

  if (A.at(0) == 0) {
    cout << 0 << endl;
    return 0;
  }

  sort_g(A);
  Mint M = 1;
  rep(i, N) {
    M *= A.at(i);
    if (M > D) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << M << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

const ll D = pow(10, 18);

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

  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);

  Mint M = 1;
  rep(i, N) { M *= A.at(i); }

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

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

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

  unsigned long long ans = 1;
  bool f = false;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    unsigned long long c = ans * a[i];
    if ((c / ans) != a[i]) {
      f = true;
      break;
    }

    ans *= a[i];
  }
  rep(i, n) {
    if (a[i] == 0) {
      f = false;
      cout << "0";
      return 0;
    }
  }
  if (ans > 1000000000000000000)
    f = true;
  if (f == true)
    cout << "-1";
  else
    cout << ans;
  return 0;
}


Error: WA

Fixed submission:

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

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

  unsigned long long ans = 1;
  bool f = false;
  rep(i, n) {
    cin >> a[i];
    unsigned long long c = ans * a[i];
    if (c / ans != a[i])
      f = true;

    ans *= a[i];
  }

  if (ans > 1000000000000000000)
    f = true;

  if (ans == 0)
    f = false;

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

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

int main() { /* ここに書く */

  long long N, ans, B, Q;
  ans = 1;
  Q = 0;

  cin >> N;

  for (int i = 0; i < N; i++) {

    cin >> B;

    if (B == 0) {
      cout << 0 << endl;
      Q = 2;
      break;
    }

    if (ans > 1000000000000000000 / B) {

      Q = 1;
    }

    ans = ans * B;
  }

  if (Q == 0) {
    cout << ans << endl;
  }

  else if (Q == 1) {
    cout << -1 << endl;
  }
}

Error: 0

Fixed submission:

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

int main() { /* ここに書く */

  long long N, ans, B, Q, C;
  ans = 1;
  Q = 0;

  cin >> N;

  for (int i = 0; i < N; i++) {

    cin >> B;

    if (B == 0) {
      cout << 0 << endl;
      Q = 2;
      break;
    }

    C = ans;
    ans = ans * B;

    if (B > 1000000000000000000 / C) {

      Q = 1;
    }

    if (ans / B != C) {

      Q = 1;
    }

    if (ans < 0) {

      Q = 1;
    }
  }

  if (Q == 0) {
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mod 1000000007
#define p 1000000000000000000
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
typedef long long int ll;
int main() {
  FIO;
  // test
  {
    ll n, i, x;
    cin >> n;
    ll a[n];
    ll flag = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 0) {
        flag = 1;
      }
    }
    if (flag == 1) {
      cout << 0 << endl;
    } else {
      ll ans = 1, flag = 0;
      for (i = 0; i < n; i++) {
        x = p / ans;
        if (a[i] > x) {
          cout << -1 << endl;
          flag = 1;
          i = n;
        }
        ans *= a[i];
      }
      if (flag == 0 && ans <= p && ans >= 1) {
        cout << ans << endl;
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mod 1000000007
#define p 1000000000000000000
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
typedef long long int ll;
int main() {
  FIO;
  // test
  {
    ll n, i, x;
    cin >> n;
    ll a[n];
    ll flag = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 0) {
        flag = 1;
      }
    }
    if (flag) {
      cout << 0 << endl;
    } else {
      ll ans = 1, flag = 0;
      for (i = 0; i < n; i++) {
        x = p / ans;
        if (a[i] > x) {
          cout << -1 << endl;
          flag = 1;
        }
        ans *= a[i];
      }
      if (flag == 0 && ans <= p && ans >= 1) {
        cout << ans << endl;
      }
    }
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

const ll INF = 1000000000000000001LL;

void solve() {
  int n;
  scanf("%d", &n);
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ll a;
    scanf("%lld", &a);
    if (a <= INF / ans)
      ans *= a;
    else
      ans = INF;
    if (ans == 0)
      break;
  }
  if (ans == INF)
    ans = -1;
  printf("%lld\\n", ans);
}

int main() {

  solve();
  return 0;
}


Error: WA

Fixed submission:

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

const ll INF = 1e18;

void solve() {
  int n;
  scanf("%d", &n);
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ll a;
    scanf("%lld", &a);
    if (a <= INF / ans)
      ans *= a;
    else
      ans = INF;
  }
  if (ans == INF)
    ans = -1;
  printf("%lld\\n", ans);
}

int main() {

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

/// بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int i, n, p, m, x = 0;
  cin >> n;
  ll int ara[n];
  for (i = 0; i < n; i++) {
    cin >> ara[i];
    if (ara[i] == 0) {
      x = 1;
    }
  }
  p = 1;
  if (x == 1) {
    cout << 0 << endl;
    return 0;
  }
  p = ara[0] * p;
  for (i = 1; i < n; i++) {
    m = ara[i] * p;
    if (m > 1000000000000000000 || m < 0 || m < p) {
      cout << -1 << endl;
      return 0;
    }
    p = m;
  }
  cout << m << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

#define ff first
#define ss second
// #define ll 				long long int
#define dd double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define modp 998244353
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }

void solve() {
  int n;
  cin >> n;
  long long int a[n];
  cpp_int res = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    res = res * a[i];
  }
  if (res > 1000000000000000000) {
    cout << -1 << endl;
    return;
  }
  cout << res << endl;
}

int32_t main() {
  FIO
  // aks();
  // w(t)
  {
    solve();
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/*
 * problem:
 * method:
 * date:
 */
#include <iostream>
#define LL long long
const LL MAXN = 10e5, MAX = 1e18;
using namespace std;
LL x[100010];
int main() {
  int i;
  LL n, a, res = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%lld", x + i);
    if (x[i] == 0)
      res = 0;
  }
  if (res) {
    for (i = 0; i < n; i++) {
      if (x[i] <= MAX / res) {
        res *= x[i];
      } else {
        res = -1;
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Error: WA

Fixed submission:

/*
 * problem:
 * method:
 * date:
 */
#include <iostream>
#define LL long long
const LL MAXN = 10e5, MAX = 1e18;
using namespace std;
LL x[10010];
int main() {
  int i;
  LL n, a, res = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%lld", x + i);
    if (x[i] == 0)
      res = 0;
  }
  if (res) {
    for (i = 0; i < n; i++) {
      if (x[i] < MAX / res) {
        res *= x[i];
      } else {
        res = -1;
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

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

  ll INF = pow(10, 18);

  ll A, ans = 1;
  bool zero = false, overflow = false;
  rep(i, 0, N - 1) {
    cin >> A;
    if (A == 0)
      zero = true;
    else if (INF / A < ans)
      overflow = true;
    ans *= A;
  }

  if (zero)
    cout << 0 << endl;
  else if (overflow)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

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

  ll INF = pow(10, 18);

  ll A, ans = 1;
  bool zero = false, overflow = false;
  rep(i, 0, N - 1) {
    cin >> A;
    if (A == 0)
      zero = true;
    if (INF / A < ans)
      overflow = true;
    ans *= A;
  }

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

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

int main() {
  long long n;
  cin >> n;
  long long ans, a;
  ans = 1;
  bool ng = false;
  bool end = false;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      end = true;
      break;
    }
    if (1000000000000000000 / a < ans) {
      ng = true;
    } else if (ng == false) {
      ans *= a;
    }
  }
  if (end == false && ng) {
    cout << "-1" << endl;
  } else if (ng == false) {
    cout << ans << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long ans, a;
  ans = 1;
  bool ng = false;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
      cout << "0" << endl;
      ans = 0;
    }
    if (1000000000000000000 / a < ans) {
      ng = true;
    } else if (ng == false) {
      ans *= a;
    }
  }
  if (ans != 0 && ng) {
    cout << "-1" << endl;
  } else if (ng) {
    cout << ans << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int N;

  cin >> N;

  vector<long long> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i];

    if (A[i] == 0) {
      cout << "0";
      return 0;
    }
  }

  long long total = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] <= 1000000000000000000 / total) {
      total *= A[i];
    } else {
      cout << "-1";
      return 0;
    }
  }

  cout << total;
}

Error: WA

Fixed submission:

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

using namespace std;

int main() {
  int N;

  cin >> N;

  vector<int> A(N);

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

  long long total = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] <= 1000000000000000000 / total) {
      total *= A[i];
    } else {
      cout << "-1";
      return 0;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;
mt19937_64 rng(58);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long ans = 1;
  bool larger = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (ans && a >= (1000000000000000001ll) / ans +
                        (1000000000000000001ll % ans > 0)) {
      larger = true;
    } else {
      ans *= a;
    }
  }
  if (ans != 0 && larger) {
    cout << -1 << '\\n';
  } else {
    cout << ans << '\\n';
  }
}

Error: 0
1000000000000000001
1000000000


Fixed submission:

#include <bits/stdc++.h>

using namespace std;
mt19937_64 rng(58);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long ans = 1;
  bool larger = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    cerr << (1000000000000000001ll) / ans << '\\n';
    if (a >=
        (1000000000000000001ll) / ans + (1000000000000000001ll % ans > 0)) {
      larger = true;
    } else {
      ans *= a;
    }
  }
  if (ans != 0 && larger) {
    cout << -1 << '\\n';
  } else {
    cout << ans << '\\n';
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  long long a[N], b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] > 1e18) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] != 1)
      b[i] = a[i] - 1;
    else
      b[i] = a[i];
  }
  long long ans = a[0], ans2 = a[0] + 1;
  for (int i = 1; i < N; i++) {
    ans2 *= b[i];
    if (ans2 < 0 || ans2 > 1000000000000000000 || ans2 % b[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < N; i++) {
    ans *= a[i];
    if (ans < 0 || ans > 1000000000000000000 || ans % a[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  long long a[N], b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] > 1e18) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] != 1)
      b[i] = a[i] - 1;
  }
  long long ans = a[0], ans2 = a[0] + 1;
  for (int i = 1; i < N; i++) {
    ans2 *= b[i];
    if (ans2 < 0 || ans2 > 1000000000000000000 || ans2 % b[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < N; i++) {
    ans *= a[i];
    if (ans < 0 || ans > 1000000000000000000 || ans % a[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  unsigned long long int nm[100000];
  long double ans = 1;
  for (int i = 0; i < n; i++) {
    scanf("%llu", &nm[i]);
    if (nm[i] == 0) {
      printf("0");
      return 0;
    }
  }

  for (int i = 0; i < n; i++) {
    ans *= nm[i];

    if (ans > 1000000000000000000 || ans < 0) {
      printf("-1");
      return 0;
    }
  }

  printf("%lld", (long long int)ans);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  unsigned long long int nm, ans = 1;
  bool flag = false;
  while (n >= 0) {
    n--;
    scanf("%llu", &nm);

    ans *= nm;

    if (nm == 0) {
      printf("0\\n");
      while (n--)
        scanf("%llu", ans);
      flag = true;
    }
    if (ans > 1000000000000000000) {
      printf("-1\\n");
      while (n--)
        scanf("%llu", ans);
      flag = true;
    }
  }
  if (!flag)
    printf("%llu\\n", ans);

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

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  unsigned long long x;
  unsigned long long z = 1;
  bool flag = false;
  bool zeroflag = false;
  for (int i = 0; i < n; i++) {
    cin >> x;

    if (x == 0) {
      zeroflag = true;
      break;
    }
    if (x <= 1000000000000000000 / z) {
      z = z * x;
    } else {
      flag = true;
    }
  }
  if (!zeroflag) {
    if (!flag) {
      cout << z << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  unsigned long long x;
  unsigned long long z = 1;
  bool flag = false;
  bool zeroflag = false;
  for (int i = 0; i < n; i++) {
    cin >> x;

    if (x == 0) {
      zeroflag = true;
    }
    if (x <= 1000000000000000000 / z) {
      z = z * x;
    } else {
      flag = true;
    }
  }
  if (!zeroflag) {
    if (!flag) {
      cout << z << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    cout << 0 << endl;
  }

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

#include <iostream>
using namespace std;

#include <algorithm>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

constexpr long long int ma = 1000000000000000000LL;

int main() {

  long long int n;
  cin >> n;

  mp::cpp_int ans = 1;
  for (long long int i = 0; i < n; i++) {
    long long int in;
    cin >> in;
    ans *= in;
    if (ans > ma)
      ans = ma + 1;
  }
  if (ans > ma) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#include <algorithm>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

int main() {

  long long int n;
  cin >> n;

  mp::cpp_int ans = 1;
  for (long long int i = 0; i < n; i++) {
    long long int in;
    cin >> in;
    ans *= in;
  }
  if (ans > 1000000000000000000LL) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

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

#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long long int n, b;
  long long int p = 1;
  int i;
  cin >> n;
  b = pow(10, 18);
  long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      b = 1;
      p = 0;
      break;
    }
    b = b / a[i];
    p = p * a[i];
  }

  if (b == 0) {
    cout << -1;
  } else {
    cout << p;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long long int n, b;
  long long int p = 1;
  int i;
  cin >> n;
  long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    p = p * a[i];
  }
  b = pow(10, 18);
  for (i = 0; i < n; i++) {
    b = b / a[i];
  }

  if (b == 0) {
    cout << -1;
  } else {
    cout << p;
  }
  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>;

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

int main() {
  int n;
  cin >> n;
  ll a[n];
  ll z = pow(10, 18);
  __int128 s = 1;
  bool ss = true;

  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      ss = false;
    }
  }
  if (ss) {
    rep(i, n) {
      s *= a[i];
      // cout << s << endl;
      if (s > z || s < 0) {
        s = -1;
        break;
      }
    }
  }
  if (ss) {
    cout << s << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Error: TLE

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 int INF = 1001001001;
int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s, 1 << n) {
    int cost = 0;
    vector<int> d(m);
    rep(i, n) {
      if (s >> i & 1) {
        cost += c[i];
        rep(j, m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j, m) if (d[j] < x) ok = false;
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}