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

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) (min(a, b) <= (x) && (x) <= max(a, b)) // hei
#define DUPLE(a, b, c, d)                                                      \\
  (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589

#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

//[a, b)
#define Getsum(ar, a, b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

struct Edge {
  int from, to;
  ll w;
  bool operator<(const Edge &rhs) const {
    return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
  }
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;

inline ll ksum(ll n, ll k) { return k * (2 * n - k - 1); }

pii updtp2(pii p, int nw) {
  if (p.first == -1)
    p.first = nw;
  else if (p.second == -1)
    p.second = nw;
  else if (p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  } else if (p.second >= nw)
    p.second = nw;
  return p;
}

typedef ll Hash;

#define isValid(y, x) (y >= 0 && y < n && x >= 0 && x < m)
const pii Dir[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int main() {
  int n;
  cin >> n;

  vector<ll> a(n);
  vector<pii> b(n);

  int cnt[19][19] = {};

  ll ans = 0;

  REP(i, n) {
    string sss;
    cin >> sss;
    int idx = sss.find_first_of(".");
    string ss, sd;
    if (idx != -1) {
      sd = sss.substr(0, idx);
      ss = sss.substr(idx + 1, sss.length() - idx - 1);
    } else
      sd = sss;

    if (ss.size() < 9)
      ss += string(9 - ss.size(), '0');
    sd += ss;
    a[i] = atol(sd.c_str());

    ll buf = a[i];
    while (buf % 2 == 0) {
      buf /= 2;
      b[i].first++;
    }
    while (buf % 5 == 0) {
      buf /= 5;
      b[i].second++;
    }

    rep(j, 18 - min(18, b[i].first), 19) {
      rep(k, 18 - min(18, b[i].second), 19) { ans += cnt[j][k]; }
    }

    cnt[min(18, b[i].first)][min(18, b[i].second)]++;
  }

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) (min(a, b) <= (x) && (x) <= max(a, b)) // hei
#define DUPLE(a, b, c, d)                                                      \\
  (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589

#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

//[a, b)
#define Getsum(ar, a, b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

struct Edge {
  int from, to;
  ll w;
  bool operator<(const Edge &rhs) const {
    return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
  }
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;

inline ll ksum(ll n, ll k) { return k * (2 * n - k - 1); }

pii updtp2(pii p, int nw) {
  if (p.first == -1)
    p.first = nw;
  else if (p.second == -1)
    p.second = nw;
  else if (p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  } else if (p.second >= nw)
    p.second = nw;
  return p;
}

typedef ll Hash;

#define isValid(y, x) (y >= 0 && y < n && x >= 0 && x < m)
const pii Dir[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int main() {
  int n;
  cin >> n;

  vector<ll> a(n);
  vector<pii> b(n);

  int cnt[18][18] = {};

  ll ans = 0;

  REP(i, n) {
    string sss;
    cin >> sss;
    int idx = sss.find_first_of(".");
    string ss, sd;
    if (idx != -1) {
      sd = sss.substr(0, idx);
      ss = sss.substr(idx + 1, sss.length() - idx - 1);
    } else
      sd = sss;

    if (ss.size() < 9)
      ss += string(9 - ss.size(), '0');
    sd += ss;
    a[i] = atol(sd.c_str());

    ll buf = a[i];
    while (buf % 2 == 0) {
      buf /= 2;
      b[i].first++;
    }
    while (buf % 5 == 0) {
      buf /= 5;
      b[i].second++;
    }

    rep(j, 18 - min(18, b[i].first), 18) {
      rep(k, 18 - min(18, b[i].second), 18) { ans += cnt[j][k]; }
    }

    cnt[min(18, b[i].first)][min(18, b[i].second)]++;
  }

  cout << ans << endl;
  return 0;
}