Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define max 1000000
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define lli long long int
#define endl '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases cout << "Case " << ++Case << ": ";
#define __test                                                                 \
  int tt;                                                                      \
  int Case = 0;                                                                \
  cin >> tt;                                                                   \
  while (tt--)
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a, n)                                                       \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define CopyArray(a, temp, n)                                                  \
  for (int i = 0; i < n; i++)                                                  \
    temp[i] = a[i];
#define PrintArray(a, n)                                                       \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";                                                       \
  cout << endl;
using namespace std;

int main() {
#ifdef Niloy
  read("input.txt");
  write("output.txt");
#endif

  int n;
  cin >> n;
  long long arr[10010];

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

  long long int mul = 1;

  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      printf("0\n");
      return 0;
    }
  }

  for (int i = 0; i < n; i++) {
    if (arr[i] <= 1000000000000000000 / mul) {
      mul *= arr[i];
    } else {
      printf("-1\n");
      return 0;
    }
  }

  printf("%lld\n", mul);
  cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define max 1000000
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define lli long long int
#define endl '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases cout << "Case " << ++Case << ": ";
#define __test                                                                 \
  int tt;                                                                      \
  int Case = 0;                                                                \
  cin >> tt;                                                                   \
  while (tt--)
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a, n)                                                       \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define CopyArray(a, temp, n)                                                  \
  for (int i = 0; i < n; i++)                                                  \
    temp[i] = a[i];
#define PrintArray(a, n)                                                       \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";                                                       \
  cout << endl;
using namespace std;

int main() {
#ifdef Niloy
  read("input.txt");
  write("output.txt");
#endif

  int n;
  cin >> n;
  long long arr[100010];

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

  long long int mul = 1;

  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) {
      printf("0\n");
      return 0;
    }
  }

  for (int i = 0; i < n; i++) {
    if (arr[i] <= 1000000000000000000 / mul) {
      mul *= arr[i];
    } else {
      printf("-1\n");
      return 0;
    }
  }

  printf("%lld\n", mul);
  cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  return 0;
}