Problem p02658 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

// headers {{{
using namespace std;
// using namespace rel_ops;

typedef long long int64;
typedef unsigned long long uint64;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int INF = 0x7FFFFFFF;
template <class T> inline bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <class T> inline bool checkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
template <class T> inline T sqr(T x) { return x * x; }
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A, B) make_pair(A, B)
#define PB(X) push_back(X)
#define mem(a, b) memset(a, b, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ff first
#define ss second
#ifdef LOCAL
#define dbg(args...) printf(args); // ##__VA_ARGS__
#define dout cout
#define out(x) (cout << #x << ": " << x << endl)
template <class T> void show(T a, int n) {
  for (int i = 0; i < n; ++i)
    cout << a[i] << ' ';
  cout << endl;
}
template <class T> void show(T a, int r, int l) {
  for (int i = 0; i < r; ++i)
    show(a[i], l);
  cout << endl;
}
#else
#define dbg(...)
#define dout                                                                   \
  if (true)                                                                    \
    ;                                                                          \
  else                                                                         \
    cout
#define out(...)
#define show(...)
#endif
// }}}

int main() {
  int N;
  while (cin >> N) {
    vector<int64> v(N);
    rep(i, N) cin >> v[i];
    int64 s = 1e18, ans = 1;
    rep(i, N) {
      s /= v[i];
      ans *= v[i];
    }
    if (s < 1)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

// headers {{{
using namespace std;
// using namespace rel_ops;

typedef long long int64;
typedef unsigned long long uint64;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int INF = 0x7FFFFFFF;
template <class T> inline bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <class T> inline bool checkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
template <class T> inline T sqr(T x) { return x * x; }
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A, B) make_pair(A, B)
#define PB(X) push_back(X)
#define mem(a, b) memset(a, b, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ff first
#define ss second
#ifdef LOCAL
#define dbg(args...) printf(args); // ##__VA_ARGS__
#define dout cout
#define out(x) (cout << #x << ": " << x << endl)
template <class T> void show(T a, int n) {
  for (int i = 0; i < n; ++i)
    cout << a[i] << ' ';
  cout << endl;
}
template <class T> void show(T a, int r, int l) {
  for (int i = 0; i < r; ++i)
    show(a[i], l);
  cout << endl;
}
#else
#define dbg(...)
#define dout                                                                   \
  if (true)                                                                    \
    ;                                                                          \
  else                                                                         \
    cout
#define out(...)
#define show(...)
#endif
// }}}

int main() {
  int N;
  while (cin >> N) {
    auto solve = [&]() {
      vector<int64> v(N);
      rep(i, N) cin >> v[i];
      int64 s = 1e18, ans = 1;
      rep(i, N) {
        if (v[i] == 0) {
          cout << 0 << endl;
          return;
        }
        s /= v[i];
        ans *= v[i];
      }
      if (s < 1)
        cout << -1 << endl;
      else
        cout << ans << endl;
    };
    solve();
  }
  return 0;
}