Problem p02588 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n)-1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void prn(vector<T> &v) {
  int n = sz(v);
  REP(i, n) cout << v[i] << ' ';
}
template <class T> inline void printv(vector<T> &v) {
  int n = sz(v);
  REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');
}
template <class T> inline void printvv(vector<vector<T>> &v) {
  for (auto u : v)
    printv(u);
}
template <class T> inline void printlnv(vector<T> &v) {
  int n = sz(v);
  REP(i, n) cout << v[i] << endl;
}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  solve();
  return 0;
}

map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> m;
  ll x = n;
  ll d = 2;
  while (x > 1 && d * d <= n) {
    if (x % d == 0) {
      m[d]++;
      x /= d;
    } else {
      d++;
    }
  }
  if (x != 1)
    m[x]++;
  return m;
}

void solve() {
  int n;
  cin >> n;
  double d;
  map<pair<int, int>, ll> m;
  REP(i, n) {
    cin >> d;
    auto l = prime_factorization(llround(d * 1000000000));
    m[make_pair(l[2], l[5])]++;
  }

  ll ans = 0;
  for (auto e : m) {
    for (auto f : m) {
      if (e.first.first + f.first.first >= 18 and
          e.first.second + f.first.second >= 18) {
        if (e.first == f.first) {
          ans += e.second * (e.second - 1);
        } else {
          ans += e.second * f.second;
        }
      }
    }
  }
  cout << ans / 2 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n)-1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline void prn(vector<T> &v) {
  int n = sz(v);
  REP(i, n) cout << v[i] << ' ';
}
template <class T> inline void printv(vector<T> &v) {
  int n = sz(v);
  REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');
}
template <class T> inline void printvv(vector<vector<T>> &v) {
  for (auto u : v)
    printv(u);
}
template <class T> inline void printlnv(vector<T> &v) {
  int n = sz(v);
  REP(i, n) cout << v[i] << endl;
}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  solve();
  return 0;
}

map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> m;
  ll x = n;
  ll d = 2;
  while (x > 1 && d * d <= n) {
    if (x % d == 0) {
      m[d]++;
      x /= d;
    } else {
      d++;
    }
  }
  if (x != 1)
    m[x]++;
  return m;
}

void solve() {
  int n;
  cin >> n;
  double d;
  map<pair<int, int>, ll> m;
  REP(i, n) {
    cin >> d;
    // auto l = prime_factorization(llround(d * 1000000000));
    auto l = llround(d * 1000000000);
    int two = 0;
    while (l % 2 == 0) {
      two++;
      l /= 2;
    }
    int five = 0;
    while (l % 5 == 0) {
      five++;
      l /= 5;
    }
    m[make_pair(two, five)]++;
  }

  ll ans = 0;
  for (auto e : m) {
    for (auto f : m) {
      if (e.first.first + f.first.first >= 18 and
          e.first.second + f.first.second >= 18) {
        if (e.first == f.first) {
          ans += e.second * (e.second - 1);
        } else {
          ans += e.second * f.second;
        }
      }
    }
  }
  cout << ans / 2 << endl;
}