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

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

typedef long long ll;
typedef pair<int, int> P;

#define p_ary(ary, a, b)                                                       \\
  do {                                                                         \\
    cout << "[";                                                               \\
    for (int count = (a); count < (b); ++count)                                \\
      cout << ary[count] << ((b)-1 == count ? "" : ", ");                      \\
    cout << "]\\n";                                                             \\
  } while (0)
#define p_map(map, it)                                                         \\
  do {                                                                         \\
    cout << "{";                                                               \\
    for (auto(it) = map.begin();; ++(it)) {                                    \\
      if ((it) == map.end()) {                                                 \\
        cout << "}\\n";                                                         \\
        break;                                                                 \\
      } else                                                                   \\
        cout << "" << (it)->first << "=>" << (it)->second << ", ";             \\
    }                                                                          \\
  } while (0)

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  os << "(" << a.first << ", " << a.second << ")";
  return os;
}

const char newl = '\\n';

int main() {
  int n;
  cin >> n;
  vector<vector<int>> cnt(21, vector<int>(21, 0));
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int m = s.size(), a = -1;
    ll x = 0;
    for (int j = 0; j < m; ++j)
      if (s[j] == '.')
        a = j;
    if (a < 0)
      x = stoi(s) * 1000000000LL;
    else {
      x = stoi(s.substr(0, a)) * 1000000000LL;
      ll y = stoi(s.substr(a + 1, m - a - 1));
      for (int j = 0; j < 9 - (m - a - 1); ++j)
        y *= 10;
      x += y;
    }
    int t = -9, f = -9;
    while (x % 2 == 0)
      x /= 2, t++;
    while (x % 5 == 0)
      x /= 5, f++;
    t = min(t, 10);
    f = min(f, 10);
    for (int j = -t + 10; j < 21; ++j)
      for (int k = -f + 10; k < 21; ++k)
        ans += cnt[j][k];
    cnt[t + 10][f + 10]++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> P;

#define p_ary(ary, a, b)                                                       \\
  do {                                                                         \\
    cout << "[";                                                               \\
    for (int count = (a); count < (b); ++count)                                \\
      cout << ary[count] << ((b)-1 == count ? "" : ", ");                      \\
    cout << "]\\n";                                                             \\
  } while (0)
#define p_map(map, it)                                                         \\
  do {                                                                         \\
    cout << "{";                                                               \\
    for (auto(it) = map.begin();; ++(it)) {                                    \\
      if ((it) == map.end()) {                                                 \\
        cout << "}\\n";                                                         \\
        break;                                                                 \\
      } else                                                                   \\
        cout << "" << (it)->first << "=>" << (it)->second << ", ";             \\
    }                                                                          \\
  } while (0)

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  os << "(" << a.first << ", " << a.second << ")";
  return os;
}

const char newl = '\\n';

int main() {
  int n;
  cin >> n;
  vector<vector<int>> cnt(20, vector<int>(20, 0));
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int m = s.size(), a = -1;
    ll x = 0;
    for (int j = 0; j < m; ++j)
      if (s[j] == '.')
        a = j;
    if (a < 0)
      x = stoi(s) * 1000000000LL;
    else {
      x = stoi(s.substr(0, a)) * 1000000000LL;
      ll y = stoi(s.substr(a + 1, m - a - 1));
      for (int j = 0; j < 9 - (m - a - 1); ++j)
        y *= 10;
      x += y;
    }
    int t = -9, f = -9;
    while (x % 2 == 0)
      x /= 2, t++;
    while (x % 5 == 0)
      x /= 5, f++;
    t = min(t, 10);
    f = min(f, 10);
    for (int j = -t + 10; j < 20; ++j)
      for (int k = -f + 10; k < 20; ++k)
        ans += cnt[j][k];
    cnt[t + 10][f + 10]++;
  }
  cout << ans << endl;
}