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

//
// Created by yamunaku on 2020/08/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repl(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, n) for (int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for (int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(), (x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP << " " <<
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define CFS                                                                    \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define CST(x) cout << fixed << setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template <typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
  // CFS;
  int n;
  cin >> n;
  mtl num(101, vl(101, 0));
  rep(i, n) {
    long double d;
    cin >> d;
    int two = 0, five = 0;
    rep(t, 9) {
      d *= 10;
      two--, five--;
    }
    CST(10);
    ll dd = (ll)round(d);
    while (dd % 2 == 0) {
      dd /= 2;
      two++;
    }
    while (dd % 5 == 0) {
      dd /= 5;
      five++;
    }
    num[two + 50][five + 50]++;
  }
  ll ans = 0, ans2 = 0;
  rep(i, 101) {
    rep(j, 101) {
      if (i + i >= 100 && j + j >= 100) {
        ans2 += num[i][j] * (num[i][j] - 1) / 2;
      }
      rep(k, 101) {
        rep(l, 101) {
          if (i == k && j == l)
            continue;
          if (i + k >= 100 && j + l >= 100) {
            ans += num[i][j] * num[k][l];
          }
        }
      }
    }
  }
  cout << ans / 2 + ans2 << endl;
  return 0;
}

Error: 0

Fixed submission:

//
// Created by yamunaku on 2020/08/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repl(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, n) for (int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for (int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(), (x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP << " " <<
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define CFS                                                                    \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define CST(x) cout << fixed << setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template <typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
  // CFS;
  int n;
  cin >> n;
  mtl num(41, vl(41, 0));
  rep(i, n) {
    double d;
    cin >> d;
    int two = 0, five = 0;
    rep(t, 9) {
      d *= 10;
      two--, five--;
    }
    ll dd = (ll)(d);
    while (dd % 2 == 0) {
      dd /= 2;
      two++;
    }
    while (dd % 5 == 0) {
      dd /= 5;
      five++;
    }
    num[two + 20][five + 20]++;
  }
  ll ans = 0, ans2 = 0;
  rep(i, 41) {
    rep(j, 41) {
      if (i + i >= 40 && j + j >= 40) {
        ans2 += num[i][j] * (num[i][j] - 1) / 2;
      }
      rep(k, 41) {
        rep(l, 41) {
          if (i == k && j == l)
            continue;
          if (i + k >= 40 && j + l >= 40) {
            ans += num[i][j] * num[k][l];
          }
        }
      }
    }
  }
  cout << ans / 2 + ans2 << endl;
  return 0;
}