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

#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// #define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \\
  do {                                                                         \\
  } while (0)
#define dump(x)                                                                \\
  do {                                                                         \\
  } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

void solve() {
  int n;
  cin >> n;
  VVLL cnt(51, VLL(31));
  string s;
  REP(i, 0, n) {
    cin >> s;
    if (s.find('.') == string::npos) {
      int v = stoi(s);
      VI c(2);
      while (v > 0 && v % 2 == 0) {
        c[0]++;
        v /= 2;
      }
      while (v > 0 && v % 5 == 0) {
        c[1]++;
        v /= 5;
      }
      cnt[c[0] + 13][c[1] + 10]++;
      continue;
    }
    LL v = stol(s.substr(0, s.find('.')));
    string t = s.substr(s.find('.') + 1);
    REP(j, 0, t.size()) v *= 10;
    v += stol(t);
    int mi = t.size();
    VI c(2);
    while (v > 0 && v % 2 == 0) {
      c[0]++;
      v /= 2;
    }
    while (v > 0 && v % 5 == 0) {
      c[1]++;
      v /= 5;
    }
    if (c[0] - mi + 13 >= 0 && c[1] - mi + 10 >= 0)
      cnt[c[0] - mi + 13][c[1] - mi + 10]++;
  }
  LL ans = 0;
  REP(i, 0, 51) REP(j, 0, 31) {
    REP(k, 0, 51) REP(l, 0, 31) {
      if (i + k < 26 || j + l < 20)
        continue;
      ans += 1LL * cnt[i][j] * cnt[k][l];
      if (i == k && j == l)
        ans -= cnt[i][j];
    }
  }

  ans /= 2;
  cout << ans << endl;
}

signed main() {
  solve();

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// #define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \\
  do {                                                                         \\
  } while (0)
#define dump(x)                                                                \\
  do {                                                                         \\
  } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

void solve() {
  int n;
  cin >> n;
  // long double eps = 1e-60;
  // cout << eps << endl;
  // stod
  VVI cnt(27, VI(11));
  string s;
  REP(i, 0, n) {
    cin >> s;
    if (s.find('.') == string::npos) {
      int v = stoi(s);
      VI c(2);
      while (v > 0 && v % 2 == 0) {
        c[0]++;
        v /= 2;
      }
      while (v > 0 && v % 5 == 0) {
        c[1]++;
        v /= 5;
      }
      cnt[c[0] + 13][c[1] + 5]++;
      continue;
    }
    LL v = stol(s.substr(0, s.find('.')));
    string t = s.substr(s.find('.') + 1);
    REP(j, 0, t.size()) v *= 10;
    // cout << v << endl;
    // cout << t << endl;
    // cout << stoi(t) << endl;
    v += stoi(t);
    // cout << v << endl;
    int mi = t.size();
    VI c(2);
    while (v > 0 && v % 2 == 0) {
      c[0]++;
      v /= 2;
    }
    while (v > 0 && v % 5 == 0) {
      c[1]++;
      v /= 5;
    }
    // cnt[c[0]+10][c[1]+4]++;
    if (c[0] - mi + 13 >= 0 && c[1] - mi + 5 >= 0)
      cnt[c[0] - mi + 13][c[1] - mi + 5]++;
  }
  LL ans = 0;
  REP(i, 0, 27) REP(j, 0, 11) {
    REP(k, 0, 27) REP(l, 0, 11) {
      if (i + k < 26 || j + l < 10)
        continue;
      ans += 1LL * cnt[i][j] * cnt[k][l];
      if (i == k && j == l)
        ans -= cnt[i][j];
      // if (1LL * cnt[i][j] * cnt[k][l]) {
      //     cerr << i << ", " << j << ", " << k << ", " << l << endl;
      // }
    }

    // if (cnt[i][j]) {
    //     cerr << i << ", " << j << ": " << cnt[i][j] << endl;
    //     dump(ans);
    // }
  }

  ans /= 2;
  cout << ans << endl;
}

signed main() {
  solve();

  return 0;
}