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

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&...tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                             \\
  do {                                                                         \\
    cerr << __LINE__ << ":\\t" << #__VA_ARGS__ << " = ";                        \\
    dump(__VA_ARGS__);                                                         \\
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL << 60;
const ll MUL = 1000000000;

int main() {
  ll n;
  cin >> n;
  vector<ll> b(n);
  for (int i = 0; i < n; i++) {
    long double a;
    cin >> a;
    b[i] = a * MUL + 0.1;
  }

  vector<vector<ll>> g(21, vector<ll>(21));
  vector<ll> x(n);
  vector<ll> y(n);
  rep(i, n) {
    ll two = 0, five = 0;
    ll tmp = b[i];
    while (tmp % 2 == 0) {
      two = min(18LL, two + 1);
      tmp /= 2;
    }
    tmp = b[i];
    while (tmp % 5 == 0) {
      five = min(18LL, five + 1);
      tmp /= 5;
    }
    x[i] = two;
    y[i] = five;
    g[two + 1][five + 1]++;
  }

  rep(i, 19) g[i + 1][0] += g[i][0];
  rep(i, 19) g[0][i + 1] += g[0][i];
  rep(i, 19) rep(j, 19) g[i + 1][j + 1] += g[i + 1][j] + g[i][j + 1] - g[i][j];

  ll ans = 0;
  rep(i, n) {
    ll two = 18 - x[i];
    ll five = 18 - y[i];
    ll t = g[19][19] - g[two][19] - g[19][five] + g[two][five];
    if (x[i] * 2 >= 18 && y[i] * 2 >= 18)
      t--;
    ans += t;
  }
  ans /= 2;
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&...tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                             \\
  do {                                                                         \\
    cerr << __LINE__ << ":\\t" << #__VA_ARGS__ << " = ";                        \\
    dump(__VA_ARGS__);                                                         \\
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL << 60;
const ll MUL = 1000000000;

int main() {
  ll n;
  cin >> n;
  vector<ll> b(n);
  for (int i = 0; i < n; i++) {
    long double a;
    cin >> a;
    b[i] = a * MUL + 0.1;
  }

  vector<vector<ll>> g(21, vector<ll>(21));
  vector<ll> x(n);
  vector<ll> y(n);
  rep(i, n) {
    ll two = 0, five = 0;
    ll tmp = b[i];
    while (tmp % 2 == 0) {
      two = min(19LL, two + 1);
      tmp /= 2;
    }
    tmp = b[i];
    while (tmp % 5 == 0) {
      five = min(19LL, five + 1);
      tmp /= 5;
    }
    x[i] = two;
    y[i] = five;
    g[two][five]++;
  }

  rep(i, 19) g[i + 1][0] += g[i][0];
  rep(i, 19) g[0][i + 1] += g[0][i];
  rep(i, 19) rep(j, 19) g[i + 1][j + 1] += g[i + 1][j] + g[i][j + 1] - g[i][j];

  ll ans = 0;
  rep(i, n) {
    ll two = 17 - x[i];
    ll five = 17 - y[i];
    ll t = g[19][19] - g[two][19] - g[19][five] + g[two][five];
    if (x[i] * 2 >= 18 && y[i] * 2 >= 18)
      t--;
    ans += t;
  }
  ans /= 2;
  cout << ans << endl;

  return 0;
}