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

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

#include <sstream>
vector<string> split(const string &s, char delim) {
  vector<string> elems;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) {
    if (!item.empty()) {
      elems.push_back(item);
    }
  }
  return elems;
}

ll power10(int n) {
  ll ret = 1;
  rep(i, n) ret *= 10;
  return ret;
}

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> nums(N);
  rep(i, N) {
    auto ss = split(A[i], '.');
    if (ss.size() == 1) {
      nums[i] = stol(ss[0]) * 1000000000LL;
    } else {
      nums[i] = stol(ss[0]) * 1000000000LL +
                stol(ss[1]) * (power10(9 - ss[1].size()));
    }
  }
  vector<pii> factors(N);
  rep(i, N) {
    int a = 0, b = 0;
    while (nums[i] % 2 == 0) {
      nums[i] /= 2;
      a++;
    }
    while (nums[i] % 5 == 0) {
      nums[i] /= 5;
      b++;
    }
    factors[i] = MP(a, b);
  }
  vector<vector<ll>> prod(100, vector<ll>(100));
  rep(i, N) { prod[factors[i].first][factors[i].second]++; }
  vector<vector<ll>> cum(101, vector<ll>(101));
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      cum[i + 1][j + 1] =
          cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + prod[i][j];
    }
  }
  ll res = 0;
  rep(i, N) {
    int a = max(0, 18 - factors[i].first), b = max(0, 18 - factors[i].second);
    res += cum[100][100] - cum[100][b] - cum[a][100] + cum[a][b];
    if (factors[i].first >= 9 && factors[i].second >= 9)
      res--;
  }
  cout << res / 2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  int N;
  cin >> N;
  vector<double> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> nums(N);
  rep(i, N) { nums[i] = (ll)(A[i] * 1000000000LL); }
  vector<pll> factors(N);
  rep(i, N) {
    int a = 0, b = 0;
    while (nums[i] % 2 == 0) {
      nums[i] /= 2;
      a++;
    }
    while (nums[i] % 5 == 0) {
      nums[i] /= 5;
      b++;
    }
    factors[i] = MP(a, b);
  }
  vector<vector<int>> prod(100, vector<int>(100));
  rep(i, N) { prod[factors[i].first][factors[i].second]++; }
  vector<vector<int>> cum(101, vector<int>(101));
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      cum[i + 1][j + 1] =
          cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + prod[i][j];
    }
  }
  int res = 0;
  rep(i, N) {
    int a = 18 - factors[i].first, b = 18 - factors[i].second;
    res += cum[100][100] - cum[100][b] - cum[a][100] + cum[a][b];
    if (factors[i].first >= 9 && factors[i].second >= 9)
      res--;
  }
  cout << res / 2 << endl;
  return 0;
}