Problem p02658 (C++) — buggy submission, verdict: Runtime Error

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node *, Node *>
#define uid uniform_int_distribution
#define FILE                                                                   \\
  ifstream in("input.txt");                                                    \\
  ofstream out("output.txt");
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);                                                      \\
  cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll inf = 1000000000000000000ll;
int check(ll x, ll y) {
  ll k = inf / y;
  // cout<<k<<" "<<inf%y<<endl;
  return x < k || (k == x && inf % y == 0);
}

int main() {
  fast;
  ll a;
  cin >> a;
  ll o = 1, fl = 1, f0 = 0;
  for (int q = 0; q < a; q++) {
    ll x;
    cin >> x;
    f0 |= x == 0;
    if (x == 0) {
      o = 0;
      break;
    }
    if (check(o, x))
      o *= x;
    else
      fl = 0;
  }
  fl |= f0;
  if (!fl)
    o = -1;
  cout << o;
}

Error: WA

Fixed submission:

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node *, Node *>
#define uid uniform_int_distribution
#define FILE                                                                   \\
  ifstream in("input.txt");                                                    \\
  ofstream out("output.txt");
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);                                                      \\
  cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll inf = 1e18;
int check(ll x, ll y) {
  ll k = inf / y;
  return k < x || (k == x && inf % y == 0);
}

int main() {
  fast;
  ll a;
  cin >> a;
  ll o = 1, fl = 1;
  for (int q = 0; q < a; q++) {
    ll x;
    cin >> x;
    if (check(o, x))
      o *= x;
    else
      fl = 0;
  }
  if (!fl)
    o = -1;
  cout << o;
}