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

#include <bits/stdc++.h>

using namespace std;
#define DBG(x)                                                                 \\
  (void)(cout << "L" << __LINE__ << ": " << #x << " = " << (x) << '\\n')
#define Lower_bound(v, x)                                                      \\
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \\
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
ll a[maxn];
void run_case() {
  int n;
  cin >> n;
  bool ok = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ok = 0;
  }
  if (!ok) {
    cout << 0 << "\\n";
    return;
  }
  ll now = 1;
  ll num = 1e18;
  for (int i = 1; i <= n; i++) {
    // C;
    // DBG(now);
    if (now > num / a[i]) {
      // ok = 0;
      cout << -1 << "\\n";
      return;
    }
    now *= a[i];
  }
  cout << now << "\\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  run_case();
  cout.flush();
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>

int main() {
  int x;
  char y[6];
  scanf("%d", &x);

  for (int i = 1; i <= x; i++) {
    scanf("%s", y);
    int sum = 0;
    for (int k = 0; y[k] != '\\0'; k++) {
      sum += y[k] - '0';
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? printf("0") : ((flag) ? printf("-1") : printf("%lld\\n", prod));
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {

  int a, T[1100], result = 1;
  scanf("%d", &a);

  for (int i = 0; i < a; i++) {
    scanf("%llu", &T[i]);
  }
  for (int j = 0; j < a; j++) {
    result *= T[j];
  }

  if (result > 1e18) {
    printf("-1");
  } else {
    printf("%llu", result);
  }

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

#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], maks = 1e18, product = 1, flag = 0, zero = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > maks) ? 1 : flag;
    product *= arr[i];
    (arr[i]) ? maks /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\\n", product));
  return 0;
}


Error: WA

Fixed submission:

#include <stdio.h>

int main() {
  int N, A[10], X = -1;
  double M = 1;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    M = M * A[i];
    printf("%.0lf", M);
  }

  if (M < 0 || M > 10e18) {
    printf("%d", X);
  } else {
    printf("%.0lf", M);
  }
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cfenv>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int, int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;

#define MAX 1000000000000000000

int main(void) {
  ll n;
  cin >> n;
  ll ans = 1;
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    if (x == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (double(MAX / x) >= ans) {
      ans *= x;
    } else {
      flag = 1;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cfenv>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int, int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;

#define MAX 1000000000000000000

int main(void) {
  ll n;
  cin >> n;
  ll ans = 1;
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    if (double(MAX / x) >= ans) {
      ans *= x;
    } else {
      flag = 1;
    }
    if (x == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

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

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

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  int64_t totala = 1LL;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      totala = 0LL;
      goto OUT;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a.at(i) > 1000000000000000000 / totala) {
      totala = -1LL;
      break;
    } else {
      totala *= a.at(i);
    }
  }
OUT:
  cout << totala;
}

Error: TLE

Fixed submission:

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

int main() {
  int N = 0;
  cin >> N;
  cpp_int a0 = 0;
  cin >> a0;
  for (int i = 1; i < N; i++) {
    cpp_int ai = 0;
    cin >> ai;
    a0 *= ai;
  }
  if (a0 == 1000000000000000000) {
    cout << 1000000000000000000 << endl;
  } else if (a0 > 1000000000000000000) {
    cout << -1 << endl;
  } else {
    cout << a0 << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  long long n;
  scanf("%lld", &n);
  long long a[n + 1];
  long long hasil = 1;
  int flag = 1;
  int print;

  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0) {
      printf("0");
      flag = 0;
      break;
    }
  }

  if (flag) {
    for (int i = 0; i < n; i++) {
      if (a[i] > 1000000000000000000 / hasil) {
        flag = 0;
        break;
      }
      hasil *= a[i];
      if (i >= n - 1) {
        print = 1;
      }
    }

    if (print) {
      flag ? printf("%lld\\n", hasil) : printf("-1\\n");
    }

    return 0;
  }
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  long long int b[34], c = 1;
  long long int a;
  int i;
  scanf("%lld", &a);
  for (i = 0; i < a; i++) {
    scanf("%lld", &b[i]);
    c = c * b[i];
  }
  c > 1000000000000000000 ? printf("-1") : printf("%d", c);
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int num1[60], num2[60], ans[60];
void cheng() {
  if (num2[0] == 1 && num2[1] == 0) {
    memset(num1, 0, sizeof(num1));
  }
  if (num1[0] > 20)
    return;
  memset(ans, 0, sizeof(ans));
  int t = 0;
  for (int i = 1; i <= num1[0] + num2[0] + 2; ++i) {
    ans[i] = t;
    for (int j = 1; j <= i; ++j)
      ans[i] += num1[j] * num2[i - j + 1];
    t = ans[i] / 10;
    ans[i] %= 10;
  }
  ans[0] = num1[0] + num2[0] + 3;
  while (ans[ans[0]] == 0 && ans[0] > 0)
    ans[0]--;
  for (int i = 0; i <= ans[0]; ++i)
    num1[i] = ans[i];
};
int main() {
  num1[0] = num1[1] = 1;
  int n;
  cin >> n;
  num1[0] = 1;
  for (int i = 1; i <= n; ++i) {
    memset(num2, 0, sizeof(num2));
    string b;
    cin >> b;
    num2[0] = b.length();
    for (int j = 0; j < num2[0]; ++j)
      num2[num2[0] - j] = b[j] - '0';
    cheng();
  }
  if (num1[0] > 19) {
    cout << -1;
    return 0;
  }
  if (num1[0] == 19) {
    for (int i = 18; i >= 1; --i)
      if (num1[i]) {
        cout << -1;
        return 0;
      }
  }
  int flag = 1;
  for (int i = num1[0]; i >= 1; --i)
    cout << num1[i], flag = 0;
  if (flag)
    cout << 0;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int num1[10000], num2[10000], ans[10000];
void cheng() {
  memset(ans, 0, sizeof(ans));
  int t = 0;
  for (int i = 1; i <= num1[0] + num2[0] + 2; ++i) {
    ans[i] = t;
    for (int j = 1; j <= i; ++j)
      ans[i] += num1[j] * num2[i - j + 1];
    t = ans[i] / 10;
    ans[i] %= 10;
  }
  ans[0] = num1[0] + num2[0] + 3;
  while (ans[ans[0]] == 0 && ans[0] > 0)
    ans[0]--;
  for (int i = 0; i <= ans[0]; ++i)
    num1[i] = ans[i];
};
int main() {
  num1[0] = num1[1] = 1;
  int n;
  cin >> n;
  num1[0] = 1;
  for (int i = 1; i <= n; ++i) {
    memset(num2, 0, sizeof(num2));
    string b;
    cin >> b;
    num2[0] = b.length();
    for (int j = 0; j < num2[0]; ++j)
      num2[num2[0] - j] = b[j] - '0';
    cheng();
  }
  if (num1[0] > 19) {
    cout << -1;
    return 0;
  }
  if (num1[0] == 19) {
    for (int i = 18; i >= 1; --i)
      if (num1[i]) {
        cout << -1;
        return 0;
      }
  }
  int flag = 1;
  for (int i = num1[0]; i >= 1; --i)
    cout << num1[i], flag = 0;
  if (flag)
    cout << 0;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, int> pii;
typedef unsigned long long ULL;
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;
#define pi acos(-1)
#define INF 1e8
#define INM INT_MIN
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx, 0, sizeof(axx));
#define metf(axx) memset(axx, -1, sizeof(axx));
#define sd(ax) scanf("%d", &ax)
#define sld(ax) scanf("%lld", &ax)
#define sldd(ax, bx) scanf("%lld %lld", &ax, &bx)
#define sdd(ax, bx) scanf("%d %d", &ax, &bx)
#define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx)
#define sfd(ax) scanf("%lf", &ax)
#define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx)
#define pr(a) printf("%d\\n", a)
#define plr(a) printf("%lld\\n", a)
// 18 5 3
LL a[N];
int main() {
  int n;
  sd(n);
  for (int i = 1; i <= n; ++i)
    sld(a[i]);
  LL tmp = 1e18, ans = 1;
  bool f = false;
  for (int i = 1; i <= n; ++i) {
    LL ma = tmp / ans;
    if (a[i] > ma) {
      f = 1;
    }
    if (a[i] == 0) {
      ans = 0;
      f = 0;
      break;
    }
    if (!f)
      ans *= a[i];
  }
  if (f)
    printf("-1\\n");
  else
    plr(ans);
  //   system("pause");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, int> pii;
typedef unsigned long long ULL;
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;
#define pi acos(-1)
#define INF 1e8
#define INM INT_MIN
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx, 0, sizeof(axx));
#define metf(axx) memset(axx, -1, sizeof(axx));
#define sd(ax) scanf("%d", &ax)
#define sld(ax) scanf("%lld", &ax)
#define sldd(ax, bx) scanf("%lld %lld", &ax, &bx)
#define sdd(ax, bx) scanf("%d %d", &ax, &bx)
#define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx)
#define sfd(ax) scanf("%lf", &ax)
#define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx)
#define pr(a) printf("%d\\n", a)
#define plr(a) printf("%lld\\n", a)
// 18 5 3
LL a[N];
int main() {
  int n;
  sd(n);
  for (int i = 1; i <= n; ++i)
    sld(a[i]);
  LL tmp = 1e18, ans = 1;
  bool f = false;
  for (int i = 1; i <= n; ++i) {
    LL ma = tmp / ans;
    if (a[i] > ma) {
      f = 1;
    }
    if (a[i] == 0) {
      ans = 0;
      f = 0;
      break;
    }
    ans *= a[i];
  }
  if (f)
    printf("-1\\n");
  else
    plr(ans);
  // system("pause");
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N;
  __int128 ans = 1;
  cin >> N;

  bool ng = false;
  bool zero = false;
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      zero = true;
    }

    __int128 a = tmp;

    ans *= a;
    if (ans > 1000000000000000000) {
      ng = true;
    }
  }

  if (zero) {
    cout << 0 << endl;
  } else if (ng) {
    cout << -1 << endl;
  } else {
    long long hoge = ans;
    cout << hoge << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  long long N;
  unsigned long long ans = 1;
  cin >> N;

  bool ng = false;
  for (long long i = 0; i < N; i++) {
    unsigned long long tmp;
    cin >> tmp;
    if (tmp == 0) {
      ng = true;
    }
    if (1000000000000000000 / ans < tmp) {
      ng = true;
    }
    ans *= tmp;
  }

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

#include <bits/stdc++.h>
#define endl '\\n'
#define _USE_MATH_DEFINES
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  long long int i, num, ele[100000], big = 0;
  cin >> num;
  for (i = 0; i < num; i++)
    cin >> ele[i];
  long long int ans = 1, max = pow(10, 18);
  for (i = 0; i < num; i++) {
    if (ans != 0) {
      if (ele[i] <= (max / ans)) {
        ans *= ele[i];
      } else
        big = 1;
    }
  }
  if (big == 1 && ans != 0)
    cout << "-1";
  else
    cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
#define _USE_MATH_DEFINES
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  long long int i, num, ele[100000], big = 0;
  cin >> num;
  for (i = 0; i < num; i++)
    cin >> ele[i];
  long long int ans = 1, max = pow(10, 18);
  for (i = 0; i < num; i++) {
    if (ele[i] <= (max / ans)) {
      ans *= ele[i];
    } else
      big = 1;
  }
  if (big == 1 && ans != 0)
    cout << "-1";
  else
    cout << ans << " " << big;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 100010

using namespace std;

inline int read(int &T) {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return T = f ? -s : s;
}

const int mod = 998244353;

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n;

int a[MAXN], b = 1;

signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      puts("0");
      return 0;
    }
    b *= a[i];
    if (b > (int)(1e18) || b <= 0) {
      puts("-1");
      return 0;
    }
  }
  cout << b;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 10010

using namespace std;

inline int read(int &T) {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return T = f ? -s : s;
}

const int mod = 998244353;

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n;

int a[MAXN], b = 1;

signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      puts("0");
      return 0;
    }
    b *= a[i];
    if (b > (int)(1e18)) {
      puts("-1");
      return 0;
    }
  }
  cout << b;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  unsigned long long mul = 1, buf;
  cin >> n;
  vector<unsigned long long> a(n);
  rep(i, n) {
    cin >> buf;
    a[i] = buf;
    if (a[i] == 0) {
      cout << "0";
      return 0;
    }
  }
  rep(i, n) {
    if (mul > 1000000000000000000 / a[i]) {
      cout << "-1";
      return 0;
    }
    mul *= a[i];
  }
  cout << mul;
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n;
  unsigned long int mul = 1, buf;
  vector<unsigned long int> a(n);
  cin >> n;
  rep(i, n) {
    cin >> buf;
    a[i] = buf;
    if (a[i] == 0) {
      cout << "0";
      return 0;
    }
  }
  rep(i, n) {
    mul *= a[i];
    if (mul > 1000000000000000000) {
      cout << "-1";
      return 0;
    }
  }
  cout << mul;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(                                                          \\
    "Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

ll lim(1e18);

bool isOver(ld x, ld y) { return x * y > 1e18; }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
#endif
  int n;
  cin >> n;

  ld res = 1;
  bool ok = true;
  bool zero = false;

  while (n--) {
    ld x;
    cin >> x;

    if (isOver(res, x))
      ok = false;

    if (ok)
      res *= x;

    if (!x)
      zero = true;
  }

  if (zero)
    res = 0, ok = 1;

  if (ok)
    cout << fixed << setprecision(0) << res << endl;
  else
    puts("-1");
}


Error: WA

Fixed submission:

#pragma GCC optimize(                                                          \\
    "Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

ll lim(1e18);

ll isOver(ll x, ll y) { return x > lim / y; }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
#endif
  int n;
  scanf("%d", &n);

  ll res = 1;
  bool ok = true;

  while (n--) {
    ll x;
    scanf("%lld", &x);
    if (isOver(res, x))
      ok = false;
    if (ok)
      res *= x;
  }

  if (ok)
    printf("%lld\\n", res);
  else
    puts("-1");
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
// #include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
typedef unsigned long long ll;
typedef unsigned char Byte;
using namespace std;

bool isZero = true;

// string ans = "Yes";
ll ans = 1;
int N;
vector<ll> A;
int main() {
  cin >> N;

  ll stdd = 1;
  rep(_i, 18) stdd *= 10;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    A.push_back(tmp);
  }

  rep(i, N) {
    ll recAns = ans;
    ans *= A[i];
    if (ans > stdd || recAns != ans / A[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
// #include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
typedef unsigned long long ll;
typedef unsigned char Byte;
using namespace std;

bool isZero = true;

// string ans = "Yes";
ll ans = 1;
int N;
vector<ll> A;
int main() {
  cin >> N;

  ll stdd = 1;
  rep(_i, 18) stdd *= 10;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    A.push_back(tmp);
  }

  rep(i, N) {
    ll recAns = ans;
    ans *= A[i];
    if (ans > stdd || recAns != ans / A[i]) {
      cout << -1 << endl;
      return -1;
    }
  }

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

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

namespace mp = boost::multiprecision;

int main() {
  mp::cpp_int x = 1, a, n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a;
    x *= a;
    if (x > 1000000000000000000LL)
      x = -1;
    if (x < -1)
      x = -1;
  }
  std::cout << x << std::endl;
}

Error: TLE

Fixed submission:

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

namespace mp = boost::multiprecision;

int main() {
  mp::cpp_int x = 1, a, n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a;
    x *= a;
    if (x > 1000000000000000000LL)
      x = -1;
  }
  std::cout << x << std::endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
  int n, Count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      Count++;
    }
  }
  if (Count > 0) {
    cout << 0 << endl;
    return 0;
  }
  long long sum = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / sum) {
      // This condition is equivalent to sum*a[i] <=10ˆ18
      sum = sum * a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long sum = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1000000000000000000 / sum) {
      // This condition is equivalent to sum*a[i] <=10ˆ18
      sum = sum * a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 1e18;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e6;

void solve() {
  int n;
  cin >> n;
  int res = 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (res && INF / res < x) {
      res = INF + 1;
    } else {
      res *= x;
    }
  }
  cout << (res > INF ? -1 : res);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed;
  cout.precision(12);
  srand(time(0));
  int t = 1;
  // int t;
  // cin >> t;
  while (t--)
    solve();
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 1e18;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e6;

void solve() {
  int n;
  cin >> n;
  int res = 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (INF / res < x) {
      res = INF + 1;
    } else {
      res *= x;
    }
  }
  cout << (res > INF ? -1 : res);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed;
  cout.precision(12);
  srand(time(0));
  int t = 1;
  // int t;
  // cin >> t;
  while (t--)
    solve();
}