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

#include <bits/stdc++.h>
#define rep(a, n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
// using Graph = vector<vector<ll> >;
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;
}
const ll INF = 1e9;

// input
ll n;
vector<ll> a;

ll d[60][60];

int main() {
  // input
  cin >> n;
  a.resize(n);
  rep(i, n) {
    string s;
    cin >> s;
    bool flag = false;
    ll x = 0;
    ll res = 0;
    rep(j, s.size()) {
      if (res == 9)
        continue;
      if (s[j] == '.')
        flag = true;
      else {
        x = x * 10 + s[j] - '0';
        if (flag)
          res++;
      }
    }
    while (res < 9) {
      x *= 10;
      res++;
    }
    a[i] = x;
  }
  rep(i, n) {
    ll t = 0;
    ll s = 0;
    while (a[i] % 2 == 0) {
      t++;
      a[i] /= 2;
    }
    while (a[i] % 5 == 0) {
      s++;
      a[i] /= 5;
    }
    d[t][s]++;
  }
  ll ans = 0;

  rep(i, 60) {
    rep(j, 60) {
      rep(k, 60) {
        rep(l, 60) {
          if (i == k && j == l)
            continue;
          if (i + k < 18 || j + l < 18)
            continue;
          ans += d[i][j] * d[k][l];
        }
      }
    }
  }
  ans /= 2;

  // 自分自身のペアを考えるの忘れない
  ll res = 0;
  rep(i, 60) {
    rep(j, 60) {
      if (i * 2 < 18 || j * 2 < 18)
        continue;
      res += d[i][j] * (d[i][j] - 1) / 2;
    }
  }
  cout << ans + res << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(a, n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
using Graph = vector<vector<ll>>;
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;
}
const ll INF = 1e18;

// 入力
ll n;
vector<P> a;

P rat(double d) {
  ll bunshi = d * 1e4;
  ll bunbo = 1e4;
  for (ll i = 2; i * i <= 1e4; i++) {
    while ((bunshi % i == 0) && (bunbo % i == 0)) {
      bunshi /= i;
      bunbo /= i;
    }
  }
  return {bunbo, bunshi};
}

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  cin >> n;
  rep(i, n) { // 入力を分数に変換してvecに保存
    double A;
    cin >> A;
    ll f = A * (1e9);
    ll s = A * (1e4);
    s *= (1e5);
    if (f != s)
      continue;
    auto p = rat(A);
    a.push_back(p);
  }
  vector<map<ll, ll>> seen(1e4 + 5);
  ll l = a.size();
  ll ans = 0;
  rep(i, l) {
    ll bunbo = a[i].first;
    ll bunshi = a[i].second;
    auto div = divisor(bunshi);
    /*rep(j,div.size()){//今までに登場した中で分母が分子の約数かつ分子が分母の倍数
        ll x = div[j];
        ans += seen[x][bunbo];
    }
    */
    ans += seen[bunshi][bunbo];
    auto div2 = divisor(bunbo);
    rep(j, div2.size()) { // seenの更新
      ll x = div2[j];
      rep(k, div.size()) { seen[x][k]++; }
    }
  }
  cout << ans << endl;
  return 0;
}