Problem p02659 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O2")

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

typedef long long int ll;
typedef unsigned long long int ull;

#define test(t)                                                                \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define all(a) a.begin(), a.end()
#define endl "\n"
#define deb(x) cout << #x << "--" << x << "--" << endl;
#define deb2(x, y)                                                             \
  cout << #x << "-" << x << "-"                                                \
       << " ~~ " << #y << "-" << y << "-" << endl;
#define deb3(x, y, z)                                                          \
  cout << #x << "-" << x << "-"                                                \
       << " ~~ " << #y << "-" << y << "-"                                      \
       << " ~~ " << #z << "-" << z << "-" << endl;
#define deba(arr)                                                              \
  cout << #arr << " ~ [ ";                                                     \
  for (auto n : arr)                                                           \
    cout << n << " ";                                                          \
  cout << "]" << endl;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

#define mx9 1000000007
#define mx7 10000007
#define mx6 1000006
#define mx5 200005
#define inf 1 << 30
#define eps 1e-9
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884L

void solve() {
  ll n;
  cin >> n;
  ll a[n];
  f(i, 0, n) cin >> a[i];
  ll pro = 1;
  f(i, 0, n) {
    pro *= a[i];
    if (pro > 1e18) {
      cout << "-1" << endl;
      return;
    }
  }
  cout << pro << endl;
}
int main() {
  fast;
  // test(t)
  solve();
  return 0;
}


Fixed submission:
#pragma GCC optimize("O2")

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

typedef long long int ll;
typedef unsigned long long int ull;

#define test(t)                                                                \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define all(a) a.begin(), a.end()
#define endl "\n"
#define deb(x) cout << #x << "--" << x << "--" << endl;
#define deb2(x, y)                                                             \
  cout << #x << "-" << x << "-"                                                \
       << " ~~ " << #y << "-" << y << "-" << endl;
#define deb3(x, y, z)                                                          \
  cout << #x << "-" << x << "-"                                                \
       << " ~~ " << #y << "-" << y << "-"                                      \
       << " ~~ " << #z << "-" << z << "-" << endl;
#define deba(arr)                                                              \
  cout << #arr << " ~ [ ";                                                     \
  for (auto n : arr)                                                           \
    cout << n << " ";                                                          \
  cout << "]" << endl;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

#define mx9 1000000007
#define mx7 10000007
#define mx6 1000006
#define mx5 200005
#define inf 1 << 30
#define eps 1e-9
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884L

void solve() {
  long double a, b;
  cin >> a >> b;
  ll pro = floor(a * b);
  cout << pro << endl;
}
int main() {
  fast;
  // test(t)
  solve();
  return 0;
}