Problem p02588 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T> T gcd(T a, T b) {
  return ((a % b == 0) ? b : gcd(b, a % b));
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
public:
  int n;
  vector<string> a;
  vector<vector<int>> cnt, sum;
  vector<int> c2, c5;
  const int geta = 9;
  Solver(LL n)
      : n(n), a(n), cnt(100, vector<int>(100)), sum(100, vector<int>(100)),
        c2(n), c5(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      int d = 0;
      int tmp = a[i].find('.');
      if (tmp != -1) {
        d = -(a[i].length() - tmp - 1);
      }
      LL b = 0;
      for (int j = 0; j < a[i].length(); ++j) {
        if (a[i][j] != '.') {
          b *= 10;
          b += a[i][j] - '0';
        }
      }
      int cnt2 = d, cnt5 = d;
      while (b > 0 && b % 2 == 0) {
        cnt2++;
        b /= 2;
      }
      while (b > 0 && b % 5 == 0) {
        cnt5++;
        b /= 5;
      }
      DBG(a[i], cnt2, cnt5)
      cnt[cnt2 + geta][cnt5 + geta]++;
      c2[i] = cnt2;
      c5[i] = cnt5;
    }
    sum = cnt;
    for (int i = (int)sum.size() - 1; i >= 0; --i) {
      for (int j = (int)sum[i].size() - 2; j >= 0; --j) {
        sum[i][j] += sum[i][j + 1];
      }
    }

    for (int i = (int)sum.size() - 2; i >= 0; --i) {
      for (int j = (int)sum[i].size() - 1; j >= 0; --j) {
        sum[i][j] += sum[i + 1][j];
      }
    }

    LL ans = 0, same = 0;
    for (int i = 0; i < n; ++i) {
      DBG(sum[-c2[i] + geta][-c5[i] + geta])
      if (c2[i] >= 0 && c5[i] >= 0)
        same++;
      ans += sum[-c2[i] + geta][-c5[i] + geta];
    }

    cout << (ans - same) / 2 << endl;
  }
}; // namespace Problem

} // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T> T gcd(T a, T b) {
  return ((a % b == 0) ? b : gcd(b, a % b));
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
public:
  int n;
  vector<string> a;
  vector<vector<int>> cnt, sum;
  vector<int> c2, c5;
  const int geta = 9;
  Solver(LL n)
      : n(n), a(n), cnt(100, vector<int>(100)), sum(100, vector<int>(100)),
        c2(n), c5(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      int d = 0;
      int tmp = a[i].find('.');
      if (tmp != -1) {
        d = -(a[i].length() - tmp - 1);
      }
      LL b = 0;
      for (int j = 0; j < a[i].length(); ++j) {
        if (a[i][j] != '.') {
          b *= 10;
          b += a[i][j] - '0';
        }
      }
      int cnt2 = d, cnt5 = d;
      while (b > 0 && b % 2 == 0) {
        cnt2++;
        b /= 2;
      }
      while (b > 0 && b % 5 == 0) {
        cnt5++;
        b /= 5;
      }
      DBG(a[i], cnt2, cnt5)
      cnt[cnt2 + geta][cnt5 + geta]++;
      c2[i] = cnt2;
      c5[i] = cnt5;
    }
    sum = cnt;
    for (int i = (int)sum.size() - 1; i >= 0; --i) {
      for (int j = (int)sum[i].size() - 2; j >= 0; --j) {
        sum[i][j] += sum[i][j + 1];
      }
    }

    for (int i = (int)sum.size() - 2; i >= 0; --i) {
      for (int j = (int)sum[i].size() - 1; j >= 0; --j) {
        sum[i][j] += sum[i + 1][j];
      }
    }

    LL ans = 0, same = 0;
    for (int i = 0; i < n; ++i) {
      DBG(sum[-c2[i] + geta][-c5[i] + geta])
      if (c2[i] >= 0 && c5[i] >= 0)
        same++;
      ans += sum[max(0, -c2[i] + geta)][max(0, -c5[i] + geta)];
    }

    cout << (ans - same) / 2 << endl;
  }
}; // namespace Problem

} // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}