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

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  while (n % 2 == 0LL) {
    res[2]++;
    n /= 2;
  }
  while (n % 5 == 0LL) {
    res[5]++;
    n /= 5;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll index = 1000000000;
  vector<P> a;
  vector<vector<int>> fact(100, vector<int>(100, 0));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ll index = 9;
    ll x = 0;
    bool flag = false;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != '.') {
        if (!flag) {
          x = 10 * x + (s[i] - '0');
        } else {
          x = 10 * x + (s[i] - '0');
          index--;
        }
      } else {
        flag = true;
      }
    }
    for (int i = 0; i < index; i++) {
      x *= 10;
    }
    // cout << x << endl;
    map<ll, ll> pf = prime_factor(x);
    a.pb(mp(pf[2], pf[5]));
    fact[pf[2]][pf[5]]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll key1 = max(0LL, 18 - a[i].fs);
    ll key2 = max(0LL, 18 - a[i].sc);
    for (int j = key1; j < 100; j++) {
      for (int k = key2; k < 100; k++) {
        // cout << fact[j][k] << " ";
        ans += fact[j][k];
      }
      // cout << endl;
    }
    if (a[i].fs >= key1 && a[i].sc >= key2) {
      ans--;
    }
  }
  cout << ans / 2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll index = 1000000000;
  vector<P> a(n);
  for (int i = 0; i < n; i++) {
    double x;
    cin >> x;
    map<ll, ll> pf = prime_factor(x * index);
    a[i] = mp(pf[2], pf[5]);
  }
  sort(ALL(a));

  vector<vector<int>> fact(60, vector<int>(30, 0));
  for (int i = 0; i < n; i++) {
    // cout << a[i].fs  << " " << a[i].sc << endl;
    fact[a[i].fs][a[i].sc]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll key1 = 18 - a[i].fs;
    ll key2 = 18 - a[i].sc;
    for (int j = key1; j < 50; j++) {
      for (int k = key2; k < 25; k++) {
        ans += fact[j][k];
      }
    }
    if (a[i].fs >= key1 && a[i].sc >= key2) {
      ans--;
    }
  }
  cout << ans / 2 << endl;
  return 0;
}