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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
using namespace std;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
// s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
// vector<vector<ll>> dp(n,vector<ll>(n))
// exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD)
// % MOD;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<P> v(n);
  ll cnt[100][100];
  rep(i, 100) rep(j, 100) cnt[i][j] = 0;
  rep(i, n) {
    long double in;
    cin >> in;
    in *= 1e9;
    in += 0.1;
    ll d = in;
    int num1 = 0, num2 = 0;
    while (d % 2 == 0) {
      d /= 2;
      num1++;
    }
    while (d % 5 == 0) {
      d /= 5;
      num2++;
    }
    v[i] = {num1, num2};
    cnt[num1][num2]++;
  }
  rrep(i, 100) {
    rrep(j, 100) {
      if (i + 1 < 100)
        cnt[i][j] += cnt[i + 1][j];
      if (j + 1 < 100)
        cnt[i][j] += cnt[i][j + 1];
      if (i < 99 && j < 99)
        cnt[i][j] -= cnt[i + 1][j + 1];
    }
  }
  ll ans = 0;
  rep(i, n) {
    int x = 18 - v[i].fi, y = 18 - v[i].se;
    chmax(x, 0);
    chmax(y, 0);

    ans += cnt[x][y];
    if (v[i].fi >= 9 && v[i].se >= 9)
      ans--;
  }
  cout << ans / 2 << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
using namespace std;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
// s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
// vector<vector<ll>> dp(n,vector<ll>(n))
// exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD)
// % MOD;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> a;
  rep(i, n) {
    string s;
    cin >> s;
    ll res = 0;
    string s1 = s, s2;
    rep(j, s.size()) {
      if (s[j] == '.') {
        s1 = s.substr(0, j);
        s2 = s.substr(j + 1, s.size() - j);
        break;
      }
    }
    rep(j, s1.size()) {
      int x = s1[j] - '0';
      res = res * 10 + x;
    }
    res *= pow(10, 4);
    ll res2 = 0;
    bool ok = 1;
    rep(j, s2.size()) {
      int x = s2[j] - '0';
      if (x != 0 && j > 3) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      int k = min(4, (int)s2.size());
      rep(j, k) {
        int x = s2[j] - '0';
        res2 = res2 * 10 + x;
      }
      int z = 4 - (int)s2.size();
      if (s2.size() < 4)
        res2 *= pow(10, z);
      a.pb(res + res2);
    }
  }
  // for(ll u:a)cout<<u<<endl;
  vector<P> v;
  vector<int> vec;
  n = (int)a.size();
  rep(i, n) {
    int res = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      res++;
    }
    int res2 = 0;
    while (a[i] % 5 == 0) {
      a[i] /= 5;
      res2++;
    }
    chmin(res, 9);
    chmin(res2, 9);
    v.pb({res, res2});
    vec.pb(res);
  }
  sort(ALL(v));
  sort(ALL(vec));

  ll num[n][10];
  rep(i, n) rep(j, 10) num[i][j] = 0;

  num[n - 1][v[n - 1].se]++; // 5
  for (int j = 8; j >= 0; j--) {
    num[n - 1][j] += num[n - 1][j + 1];
  }

  for (int i = n - 2; i >= 0; i--) {
    num[i][v[i].se]++;
    for (int j = 8; j >= 0; j--) {
      num[i][j] += num[i][j + 1];
    }
    rep(j, 10) num[i][j] += num[i + 1][j];
  }
  ll ans = 0;
  rep(i, n) {
    int x = 8 - v[i].fi;
    int y = 8 - v[i].se;
    int p = (int)(lower_bound(ALL(vec), x) - vec.begin());
    // cout << p << endl;
    if (0 <= p && p < n) {
      int z = max(0, y);
      ans += num[p][z];
      if (v[i].fi >= 4 && v[i].se >= 4)
        ans--;
    }
  }
  cout << ans / 2 << endl;
}