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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<ll, Pll> PlP;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ld a;
  rep(i, N) {
    cin >> a;
    A[i] = ll(a * 1000000000 + 0.5);
  }
  vector<vector<ll>> S(40, vector<ll>(40)), B(40, vector<ll>(40));
  vector<Pll> P(N);
  rep(i, N) {
    ll cnt_2 = 0;
    ll tmp = A[i];
    while (tmp % 2 == 0) {
      cnt_2++;
      tmp /= 2;
    }
    // cnt_2 = min(cnt_2, 18LL);
    ll cnt_5 = 0;
    tmp = A[i];
    while (tmp % 5 == 0) {
      cnt_5++;
      tmp /= 5;
    }
    // cnt_5 = min(cnt_5, 18LL);
    B[cnt_2][cnt_5]++;
    P[i] = make_pair(cnt_2, cnt_5);
  }
  rep(i, 39) {
    rep(j, 39) { S[i + 1][j + 1] = S[i + 1][j] + B[i][j]; }
  }
  rep(j, 40) {
    rep(i, 39) { S[i + 1][j] += S[i][j]; }
  }
  ll ans = 0;
  rep(i, N) {
    ll t = P[i].fi;
    ll f = P[i].se;
    ll nt = max(18 - t, 0LL);
    ll nf = max(18 - f, 0LL);
    ans += S[39][39] + S[nt][nf] - S[nt][39] - S[39][nf];
    if (t >= 18 - t && f >= 18 - f) {
      ans--;
      // ans++;
    }
  }
  cout << ans / 2 << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<ll, Pll> PlP;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ld a;
  rep(i, N) {
    cin >> a;
    A[i] = ll(a * 1000000000 + 1e-10);
  }
  vector<vector<ll>> S(30, vector<ll>(30)), B(30, vector<ll>(30));
  vector<Pll> P(N);
  rep(i, N) {
    ll cnt_2 = 0;
    ll tmp = A[i];
    while (tmp % 2 == 0) {
      cnt_2++;
      tmp /= 2;
    }
    // cnt_2 = min(cnt_2, 18LL);
    ll cnt_5 = 0;
    tmp = A[i];
    while (tmp % 5 == 0) {
      cnt_5++;
      tmp /= 5;
    }
    // cnt_5 = min(cnt_5, 18LL);
    B[cnt_2][cnt_5]++;
    P[i] = make_pair(cnt_2, cnt_5);
  }
  rep(i, 29) {
    rep(j, 29) { S[i + 1][j + 1] = S[i + 1][j] + B[i][j]; }
  }
  rep(j, 30) {
    rep(i, 29) { S[i + 1][j] += S[i][j]; }
  }
  ll ans = 0;
  rep(i, N) {
    ll t = P[i].fi;
    ll f = P[i].se;
    ll nt = max(18 - t, 0LL);
    ll nf = max(18 - f, 0LL);
    ans += S[29][29] + S[nt][nf] - S[nt][29] - S[29][nf];
    if (t >= nt && f >= nf) {
      ans--;
      // ans++;
    }
  }
  cout << ans / 2 << endl;
}