Problem p02588 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n)-1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    cin >> v.at(i);
  return is;
}

template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {
  cout << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <class T>
void print(const vector<T> &v, const string &delimiter = " ") {
  rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i);
  cout << endl;
}

template <class T>
void print(const vector<vector<T>> &vv, const string &delimiter) {
  for (const auto &v : vv)
    print(v, delimiter);
}

#pragma endregion

int cnt_decimal_part(const string &s) {
  size_t p = s.find('.');
  if (p == string::npos)
    return 0;
  return s.size() - s.find('.') - 1;
}

int cnt_exp(ll x, int p) {
  int res = 0;
  while (x % p == 0) {
    res++;
    x /= p;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    string s;
    cin >> s;
    int c = cnt_decimal_part(s);
    if (0 < c)
      s.erase(s.find('.'), 1);
    rep(i, 9 - c) s.push_back('0');
    a[i] = stoll(s);
  }

  ll ans = 0;
  vector<vector<ll>> cnt(19, vector<ll>(19));

  rep(i, n) {
    int e2 = cnt_exp(a[i], 2), e5 = cnt_exp(a[i], 5);
    repr(x, 18 - e2, 19) repr(y, 18 - e5, 19) { ans += cnt[x][y]; }
    cnt[e2][e5]++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n)-1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    cin >> v.at(i);
  return is;
}

template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {
  cout << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <class T>
void print(const vector<T> &v, const string &delimiter = " ") {
  rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i);
  cout << endl;
}

template <class T>
void print(const vector<vector<T>> &vv, const string &delimiter) {
  for (const auto &v : vv)
    print(v, delimiter);
}

#pragma endregion

int cnt_decimal_part(const string &s) {
  size_t p = s.find('.');
  if (p == string::npos)
    return 0;
  return s.size() - s.find('.') - 1;
}

int cnt_exp(ll x, int p) {
  int res = 0;
  while (x % p == 0) {
    res++;
    x /= p;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    string s;
    cin >> s;
    int c = cnt_decimal_part(s);
    if (0 < c)
      s.erase(s.find('.'), 1);
    rep(i, 9 - c) s.push_back('0');
    a[i] = stoll(s);
  }

  ll ans = 0;
  vector<vector<ll>> cnt(19, vector<ll>(19));

  rep(i, n) {
    int e2 = min(18, cnt_exp(a[i], 2)), e5 = min(18, cnt_exp(a[i], 5));
    repr(x, 18 - e2, 19) repr(y, 18 - e5, 19) { ans += cnt[x][y]; }
    cnt[e2][e5]++;
  }

  cout << ans << endl;
}