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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

mt19937 mt(736);

void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  int n;

  cin >> n;

  vector<ll> arr(n);

  for (auto &it : arr) {
    string str;

    cin >> str;

    if (str.find('.') == string::npos)
      str.push_back('.');

    str.resize(str.find('.') + 10, '0');

    it = stoi(str.substr(0, str.find('.'))) * (ll)1e9 +
         stoi(str.substr(str.find('.') + 1));
  }

#ifdef LOCAL
  for (auto it : arr)
    cout << it << ' ';
  cout << endl;
#endif

  vector<vector<int>> cnt(19, vector<int>(19));

  for (auto it : arr)
    if (it != 0) {
      int two = 0, five = 0;

      while (it % 2 == 0) {
        it /= 2;
        two++;
      }

      while (it % 5 == 0) {
        it /= 5;
        five++;
      }

      cnt[min(two, (int)cnt.size() - 1)][min(five, (int)cnt.size() - 1)]++;
    } else
      cnt.back().back()++;

  auto C2 = [](ll q) { return q * (q - 1ll) / 2; };

  ll ans = 0;

  for (int two = 0; two < cnt.size(); two++)
    for (int five = 0; five < cnt.size(); five++)
      for (int i = 18 - two; i < cnt.size(); i++)
        for (int j = 18 - five; j < cnt.size(); j++) {
          if (two == i && five == j)
            ans += 2 * C2(cnt[i][j]);
          else
            ans += cnt[two][five] * (ll)cnt[i][j];
        }

  cout << ans / 2 << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cout << fixed;

#ifdef LOCAL
  auto st = clock();

  ifstream fin("../input.txt");

  do {
    solve(fin);

    cout << "===" << endl;

    string str;
    while (getline(fin, str) && str != string(max(1, (int)str.size()), '='))
      ;
  } while (fin);

  cout << setprecision(6) << "clock: " << double(clock() - st) / CLOCKS_PER_SEC
       << endl;
#else
  solve();
#endif

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

mt19937 mt(736);

void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  int n;

  cin >> n;

  vector<ll> arr(n);

  for (auto &it : arr) {
    string str;

    cin >> str;

    if (str.find('.') == string::npos)
      str.push_back('.');

    str.resize(str.find('.') + 10, '0');

    it = stoi(str.substr(0, str.find('.'))) * (ll)1e9 +
         stoi(str.substr(str.find('.') + 1));
  }

#ifdef LOCAL
  for (auto it : arr)
    cout << it << ' ';
  cout << endl;
#endif

  vector<vector<int>> cnt(19, vector<int>(19));

  for (auto it : arr)
    if (it != 0) {
      int two = 0, five = 0;

      while (it % 2 == 0) {
        it /= 2;
        two++;
      }

      while (it % 5 == 0) {
        it /= 5;
        five++;
      }

      cnt[two][five]++;
    } else
      cnt.back().back()++;

  auto C2 = [](ll q) { return q * (q - 1ll) / 2; };

  ll ans = 0;

  for (int two = 0; two < cnt.size(); two++)
    for (int five = 0; five < cnt.size(); five++)
      for (int i = 18 - two; i < cnt.size(); i++)
        for (int j = 18 - five; j < cnt.size(); j++) {
          if (two == i && five == j)
            ans += 2 * C2(cnt[i][j]);
          else
            ans += cnt[two][five] * (ll)cnt[i][j];
        }

  cout << ans / 2 << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cout << fixed;

#ifdef LOCAL
  auto st = clock();

  ifstream fin("../input.txt");

  do {
    solve(fin);

    cout << "===" << endl;

    string str;
    while (getline(fin, str) && str != string(max(1, (int)str.size()), '='))
      ;
  } while (fin);

  cout << setprecision(6) << "clock: " << double(clock() - st) / CLOCKS_PER_SEC
       << endl;
#else
  solve();
#endif

  return 0;
}