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



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

#define ll long long int
#define ld long double
#define mod 998244353
#define big 1e18 + 10
#define small -big
#define pb push_back
#define endl "\\n"

template <typename T>

void prarr(T a) {
  cerr << "[ ";

  for (auto i : a) {
    cerr << i << " ";
  }

  cerr << "]" << endl;
}

#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char *name, Arg1 &&arg1) {
  cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char *names, Arg1 &&arg1, Args &&...args) {

  const char *comma = strchr(names + 1, ',');
  cerr << "[";
  cerr.write(names, comma - names) << " : " << arg1 << "] ";
  _er(comma + 2, args...);
}

void solve() {

  ll n;
  cin >> n;

  ll A[n + 1];

  ll c0 = 0;

  for (ll i = 1; i <= n; i++) {
    cin >> A[i];
    if (A[i] == 0)
      c0++;
  }

  if (c0 >= 1) {
    cout << 0 << endl;
    return;
  }

  ll ans = 1;

  ll reach = (ll)1e18;

  for (int i = 1; i <= n; i++) {

    ll need = reach / ans;

    if (A[i] <= need) {
      ans *= A[i];
    } else {
      cout << -1 << endl;
      return;
    }
  }

  cout << ans << endl;
}

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

  int t = 1;
  // cin >> t;

  while (t--) {

    solve();
  }

  return 0;
}


Error: -11

Fixed submission:

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

#define llu unsigned long long int
#define ll long long int
#define ld long double
#define mod 998244353
#define big 1e18 + 10
#define small -big
#define pb push_back
#define endl "\\n"

template <typename T>

void prarr(T a) {
  cerr << "[ ";

  for (auto i : a) {
    cerr << i << " ";
  }

  cerr << "]" << endl;
}

#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char *name, Arg1 &&arg1) {
  cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char *names, Arg1 &&arg1, Args &&...args) {

  const char *comma = strchr(names + 1, ',');
  cerr << "[";
  cerr.write(names, comma - names) << " : " << arg1 << "] ";
  _er(comma + 2, args...);
}

void solve() {

  llu n;
  cin >> n;
  ll con = 0;

  llu A[n + 1];

  for (ll i = 1; i <= n; i++) {
    llu a;
    cin >> a;

    A[i] = a;

    if (a == 0) {
      con++;
    }
  }

  if (con) {
    cout << 0 << endl;
    return;
  }

  bool flag = true;
  llu curr = 1;
  llu prev = 1;

  for (ll i = 1; i <= n; i++) {

    curr *= A[i];

    if (curr / prev != A[i]) {
      flag = false;
      break;
    }

    prev = curr;
  }

  if (flag == false) {

    cout << -1 << endl;
    return;
  }
  if (curr <= (llu)1e18) {
    cout << curr << endl;
  } else {
    cout << -1 << endl;
  }
}

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

  ll t = 1;
  cin >> t;

  while (t--) {

    solve();
  }

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

#include <bits/stdc++.h>

using namespace std;

long long v[300000];

int main() {

  int n;
  cin >> n;
  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    if (res == -1) {
      if (v[i] == 0) {
        res = 0;
        break;
      } else
        continue;
    }
    if (res > 1000000000000000000LL / v[i]) {
      res = -1;
    } else
      res *= v[i];
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n;
  cin >> n;
  vector<int> v(n);
  long long res = 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    if (res == -1) {
      if (v[i] == 0) {
        res = 0;
        break;
      } else
        continue;
    }
    if (res > 1000000000000000000LL / v[i]) {
      res = -1;
    } else
      res *= v[i];
  }
  cout << res << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll A[MAXN];

void solve() {
  ll ans = 1;
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (ans == 0) {
      cout << 0 << endl;
      return;
    }
    if (1000000000000000000 / ans < A[i]) {
      cout << -1 << endl;
      return;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

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


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;
int n;
ll A[MAXN];

void solve() {
  ll ans = 1;
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / ans < A[i]) {
      cout << -1 << endl;
      return;
    }
    ans *= A[i];
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  solve();
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++) { // 0���܂܂�邩����
    if (A[i] == 0LL) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1LL, MAX = 1000000000000000000LL;
  for (int i = 0; i < N; i++) {
    if (MAX / ans < A[i]) { // 10^18�𒴂��Ȃ�������
      ans = -1LL;
      break;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int64_t n, a, b, i;
  bool c, d;

  c = false;
  d = false;

  cin >> n;

  a = 1LL;

  for (i = 0; i < n; i++) {
    cin >> b;
    if (100000000000000000LL / a < b) {
      c = true;
    }
    if (b == 0) {
      d = true;
    }
    a *= b;
  }

  if (a > 1000000000000000000LL) {
    a = -1;
  }
  if (a < 0) {
    a = -1;
  }
  if (c) {
    a = -1;
  }
  if (d) {
    a = 0;
  }

  cout << a << 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++)
#define ll long long
using namespace std;

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

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

  sort(A.begin(), A.end());

  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (A[i] <= 1000000000000000000 / ans) {
      ans *= A[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  ll n, a[n];
  cin >> n;
  ll ans = 1;
  rep(i, n) {
    cin >> a[i];
    ans = ans * a[i];
  }
  if (ans > 1000000000000000000) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int N = 0;
  long long res = 1;
  cin >> N;
  long long num[N];
  for (int i = 0; i < N; i++) {
    cin >> num[i];
    if (num[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (num[i] > 1000000000000000000 / res) {
      cout << -1 << endl;
      return 0;
    } else
      res *= num[i];
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N = 0;
  long *nums;
  long res = 1;
  double chkres = 1;
  cin >> N;
  nums = new long(N);
  for (int i = 0; i < N; i++) {
    cin >> nums[i];
    if (nums[i] == 0) {
      cout << 0 << endl;
      delete nums;
      return 0;
    }
  }

  for (int i = 0; i < N; i++) {
    chkres *= nums[i];
    if (chkres > 1000000000000000000) {
      cout << -1 << endl;
      delete nums;
      return 0;
    } else {
      res *= nums[i];
      if (res > 1000000000000000000) {
        cout << -1 << endl;
        delete nums;
        return 0;
      }
    }
  }
  cout << res << endl;
  delete nums;
  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>;

const ll MX = 1e18;

int main(void) {
  int n;
  cin >> n;
  bool flg = false;
  ll ans = 1;
  rep(i, n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    if (flg || MX / ans < a) {
      flg = true;
    }
    ans *= a;
  }
  if (flg)
    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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll MX = 1e18;

int main(void) {
  int n;
  cin >> n;
  bool flg = false;
  ll ans = 1;
  for (int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0;
      return 0;
    }
    if (MX / ans < a) {
      flg = true;
    }
    ans *= a;
  }
  if (flg)
    cout << -1;
  else
    cout << ans;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
string add(string a, string b) {
  string c;
  if (a.size() < b.size() || (a.size() > b.size() && a < b))
    swap(a, b);
  a += '0';
  while (b.size() < a.size())
    b += '0';
  for (int i = 0; i < a.size(); i++) {
    int s = a[i] + b[i] - 96;
    a[i + 1] += s / 10;
    c += s % 10 + 48;
  }
  return c;
}
string muti(string a, string b) {
  string sum[10], c = "0";
  if (a.size() < b.size())
    swap(a, b);
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  sum[1] = a;
  for (int i = 2; i <= 9; i++)
    sum[i] = add(sum[i - 1], a);
  for (int i = 0; i < b.size(); i++) {
    string to_add = sum[b[i] - 48];
    to_add.insert(0, i, '0');
    c = add(c, to_add);
  }
  reverse(c.begin(), c.end());
  while (c[0] == '0' && c.size() > 1)
    c.erase(0, 1);
  return c;
}
string number[100010];
int main() {
  int n;
  cin >> n;
  string sum = "1";
  for (int i = 1; i <= n; i++) {
    cin >> number[i];
    if (number[i] == "0") {
      cout << 0;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    sum = muti(number[i], sum);
    if (sum.size() > 19) {
      cout << -1;
      return 0;
    }
  }
  if (sum.size() == 19) {
    if (sum[0] > '1') {
      cout << -1;
      return 0;
    }
    for (int i = 1; i < sum.size(); i++)
      if (sum[i] > '0') {
        cout << -1;
        return 0;
      }
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
string add(string a, string b) {
  string c;
  if (a.size() < b.size() || (a.size() > b.size() && a < b))
    swap(a, b);
  a += '0';
  while (b.size() < a.size())
    b += '0';
  for (int i = 0; i < a.size(); i++) {
    int s = a[i] + b[i] - 96;
    a[i + 1] += s / 10;
    c += s % 10 + 48;
  }
  return c;
}
string muti(string a, string b) {
  string sum[10], c = "0";
  if (a.size() < b.size())
    swap(a, b);
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  sum[1] = a;
  for (int i = 2; i <= 9; i++)
    sum[i] = add(sum[i - 1], a);
  for (int i = 0; i < b.size(); i++) {
    string to_add = sum[b[i] - 48];
    to_add.insert(0, i, '0');
    c = add(c, to_add);
  }
  reverse(c.begin(), c.end());
  while (c[0] == '0' && c.size() > 1)
    c.erase(0, 1);
  return c;
}
int main() {
  int n;
  cin >> n;
  string sum = "1";
  for (int i = 1; i <= n; i++) {
    string str;
    cin >> str;
    sum = muti(str, sum);
  }
  if (sum.size() > 19) {
    cout << -1;
    return 0;
  }
  if (sum.size() == 19) {
    if (sum[0] > '1') {
      cout << -1;
      return 0;
    }
    for (int i = 1; i < sum.size(); i++)
      if (sum[i] > '0') {
        cout << -1;
        return 0;
      }
  }
  cout << sum;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  ll ans = 1LL;
  ll chk = 1000000000000000000;
  sort(v.begin(), v.end());
  if (v[0] == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (ans <= chk / v[i]) {
      ans *= v[i];
    } else {
      cout << "-1\\n";
      return 0;
    }
  }
  cout << ans;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (auto &i : v)
    cin >> i;
  long long chk = 1e18, m = 1;
  for (int i = 0; i < n; ++i) {
    if (m >= chk) {
      cout << "-1\\n";
      return 0;
    }
    m *= v[i];
  }
  cout << m;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define co(n) cout << n << endl
#define all(n) (n).begin(), (n).end()
#define pb(n, m) n.push_back(m)
#define pi(n, m) n.insert(n.begin(), m);
#define ee(n) n.erase(n.end() - 1)
#define eb(n) n.erase(n.begin())
#define check(n)                                                               \\
  reverse(all(n));                                                             \\
  rep(z, 0, n.size()) cout << n[z];                                            \\
  co("");                                                                      \\
  reverse(all(n));
using namespace std;
using bint = boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  bint c = 1, a = 1000000000000000000, b;
  int n;
  cin >> n;
  vector<ull> x(n);
  bool f = true;
  rep(i, 0, n) cin >> x[i];
  rep(i, 0, n) {
    if (x[i] == 0) {
      f = true;
      c = 0;
      break;
    }
    if (f == false)
      continue;
    if (c * x[i] > a) {
      f = false;
      c *= x[i];
      continue;
    }
    c *= x[i];
  }
  if (f == true)
    co(c);
  else
    co(-1);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define co(n) cout << n << endl
#define all(n) (n).begin(), (n).end()
#define pb(n, m) n.push_back(m)
#define pi(n, m) n.insert(n.begin(), m);
#define ee(n) n.erase(n.end() - 1)
#define eb(n) n.erase(n.begin())
#define check(n)                                                               \\
  reverse(all(n));                                                             \\
  rep(z, 0, n.size()) cout << n[z];                                            \\
  co("");                                                                      \\
  reverse(all(n));
using namespace std;
// using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ull c = 1, a = 1000000000000000000, b;
  int n;
  vector<ull> x(n);
  cin >> n;
  bool f = true;
  rep(i, 0, n) cin >> x[i];
  rep(i, 0, n) {
    if (x[i] == 0) {
      f = true;
      c = 0;
      break;
    }
    if (f == false)
      continue;
    if (c * x[i] > a) {
      f = false;
      c *= x[i];
      continue;
    }
    c *= x[i];
  }
  if (f == true)
    co(c);
  else
    co(-1);
  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 REP(i, d, n) for (int i = (d); i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define int long long
template <typename T> using vv = vector<vector<T>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using ll = long long;
constexpr ll INF = 1LL << 60;

signed main() {

  int n;
  cin >> n;

  int ans = 1;
  bool flag = false;
  bool zero = false;
  rep(i, n) {
    int a;
    cin >> a;
    if (ans != 0 && a > (ll)(1e18) / ans) {
      flag = true;
    }
    if (a == 0) {
      zero = true;
    }
    ans *= a;
  }

  if (flag && !zero) {
    cout << -1 << endl;
  } else if (zero) {
    cout << 0 << endl;
  } else {
    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 REP(i, d, n) for (int i = (d); i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define int long long
template <typename T> using vv = vector<vector<T>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using ll = long long;
constexpr ll INF = 1LL << 60;

signed main() {

  int n;
  cin >> n;

  int ans = 1;
  bool flag = false;
  bool zero = false;
  rep(i, n) {
    int a;
    cin >> a;
    if (a > (ll)(1e18) / ans) {
      flag = true;
    }
    if (a == 0) {
      zero = true;
    }
    ans *= a;
  }

  if (flag && !zero) {
    cout << -1 << endl;
  } else if (zero) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }

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

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

namespace mp = boost::multiprecision;

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

Error: TLE

Fixed submission:

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

namespace mp = boost::multiprecision;

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

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define reps(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void) {
  ll N;
  ll A;
  ll count = 1;
  cin >> N;
  bool ok = true;
  rep(i, N) {
    cin >> A;

    // cout<<A<<sp;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (A > 1000000000000000000 / count) {
      ok = false;
      count = 1;
    }
    count *= A;
  }
  if (ok)
    cout << count << endl;
  else
    cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define reps(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void) {
  ll N;
  cpp_int A;
  cpp_int count = 1;
  cin >> N;
  bool ok = true;
  rep(i, N) {
    cin >> A;
    count *= A;
    // cout<<A<<sp;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (count > 1000000000000000000) {
      ok = false;
    }
  }
  if (ok)
    cout << count << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02658 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const long double EPS = 1e-9;

#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<char> &o) {
  string a;
  in >> a;
  for (char c : a)
    o.insert(c);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> v(n);
  rep(i, n) cin >> v[i];

  if (count(v.begin(), v.end(), 0) > 0) {
    cout << 0 << endl;
    ret();
  }

  vector<long double> vl(n);
  rep(i, n) vl[i] = log10l(v[i]);

  long double keta = accumulate(vl.begin(), vl.end(), (long double)0.0);
  if (keta > 18.0) {
    cout << -1 << endl;
    ret();
  }

  unsigned long long border = 1000000000000000000ll;

  unsigned long long ans = 1;

  rep(i, n) {
    ans *= v[i];

    if (ans > border) {
      cout << -1 << endl;
      ret();
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const long double EPS = 1e-9;

#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<char> &o) {
  string a;
  in >> a;
  for (char c : a)
    o.insert(c);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;

int main() {
  int n;
  cin >> n;
  vector<mp::cpp_int> v(n);
  rep(i, n) cin >> v[i];

  if (count(v.begin(), v.end(), 0) > 0) {
    cout << 0 << endl;
    ret();
  }

  mp::cpp_int ans = 1;

  rep(i, n) { ans *= v[i]; }

  mp::cpp_int border = 1000000000000000000ll;

  if (ans > border) {
    cout << -1 << endl;
    ret();
  }

  cout << ans << endl;
}