Problem p02588 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, ll>
const ll MOD = 998244353;
const int INF = 1e9;
const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    string s;
    cin >> s;
    int m = s.size();
    rep(j, m) {
      if (s[j] == '.') {
        rep(k, 9) {
          if (j + 1 + k < m) {
            a[i] += ll(s[j + 1 + k] - '0') * pow(10, 8 - k);
          }
        }
        rep(k, j) a[i] += ll(s[j - 1 - k] - '0') * pow(10, 9 + k);
        break;
      } else if (j == m - 1) {
        rep(k, j + 1) a[i] += ll(s[j - k] - '0') * pow(10, 9 + k);
      }
    }
  }
  ll md = 1e9;
  vector<pair<int, int>> p(n);
  vector<vector<ll>> q(50, vector<ll>(50));
  rep(i, n) {
    ll b = a[i];
    int x = 0, y = 0;
    ll u = md;
    while (b % 2 == 0) {
      b /= 2;
      ++x;
    }
    while (b % 5 == 0) {
      b /= 5;
      ++y;
    }
    p[i] = {x, y};
    ++q[x][y];
  }
  ll ans = 0;
  rep(i, 50) { invrep(j, 49) q[i][j] += q[i][j + 1]; }
  rep(j, 50) { invrep(i, 49) q[i][j] += q[i + 1][j]; }

  rep(i, n) {
    ans += q[18 - p[i].first][18 - p[i].second];
    if (9 <= p[i].first && 9 <= p[i].second)
      --ans;
  }
  ans /= 2;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, ll>
const ll MOD = 998244353;
const int INF = 1e9;
const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    string s;
    cin >> s;
    int m = s.size();
    rep(j, m) {
      if (s[j] == '.') {
        rep(k, 9) {
          if (j + 1 + k < m) {
            a[i] += ll(s[j + 1 + k] - '0') * pow(10, 8 - k);
          }
        }
        rep(k, j) a[i] += ll(s[j - 1 - k] - '0') * pow(10, 9 + k);
        break;
      } else if (j == m - 1) {
        rep(k, j + 1) a[i] += ll(s[j - k] - '0') * pow(10, 9 + k);
      }
    }
  }
  ll md = 1e9;
  vector<pair<int, int>> p(n);
  vector<vector<ll>> q(50, vector<ll>(50));
  rep(i, n) {
    ll b = a[i];
    int x = 0, y = 0;
    ll u = md;
    while (b % 2 == 0) {
      b /= 2;
      ++x;
    }
    while (b % 5 == 0) {
      b /= 5;
      ++y;
    }
    p[i] = {x, y};
    ++q[x][y];
  }
  ll ans = 0;
  rep(i, 50) { invrep(j, 49) q[i][j] += q[i][j + 1]; }
  rep(j, 50) { invrep(i, 49) q[i][j] += q[i + 1][j]; }

  rep(i, n) {
    int x = max(0, 18 - p[i].first);
    int y = max(0, 18 - p[i].second);
    ans += q[x][y];
    if (9 <= p[i].first && 9 <= p[i].second)
      --ans;
  }
  ans /= 2;
  cout << ans << endl;

  return 0;
}