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

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs                                                                 \\
  {                                                                            \\
    cout << "-1\\n";                                                            \\
    return 0;                                                                  \\
  }
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template <typename T> string join(const v(T) & v) {
  stringstream s;
  rep(i, sz(v)) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
  if (sz(v))
    o << join(v);
  return o;
}

ll cnt[19][19];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vi A(N);
  rep(i, N) {
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    if (s.find('.') != string::npos) {
      int p = (int)s.find('.');
      int l = (int)s.size() - p - 1;
      a -= l;
      b -= l;
      s.erase(p, 1);
    }
    ll n;
    sscanf(s.c_str(), "%lld", &n);
    while (n % 2 == 0) {
      n /= 2;
      ++a;
    }
    while (n % 5 == 0) {
      n /= 5;
      ++b;
    }
    cnt[min(18, a + 9)][min(18, b + 9)]++;
  }
  ll ans = 0;
  rep(i, 19) rep(j, 19) srep(ii, 18 - i, 19) srep(jj, 18 - j, 19) {
    ll ad = (i == ii && j == jj) ? cnt[i][j] * (cnt[i][j] - 1)
                                 : cnt[i][j] * cnt[ii][jj];
    ans += ad;
  }
  ans /= 2;
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs                                                                 \\
  {                                                                            \\
    cout << "-1\\n";                                                            \\
    return 0;                                                                  \\
  }
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template <typename T> string join(const v(T) & v) {
  stringstream s;
  rep(i, sz(v)) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
  if (sz(v))
    o << join(v);
  return o;
}

ll cnt[14][14];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vi A(N);
  rep(i, N) {
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    if (s.find('.') != string::npos) {
      int p = (int)s.find('.');
      int l = (int)s.size() - p - 1;
      a -= l;
      b -= l;
      s.erase(p, 1);
    }
    ll n;
    sscanf(s.c_str(), "%lld", &n);
    while (n % 2 == 0) {
      n /= 2;
      ++a;
    }
    while (n % 5 == 0) {
      n /= 5;
      ++b;
    }
    cnt[a + 9][b + 9]++;
  }
  ll ans = 0;
  rep(i, 14) rep(j, 14) srep(ii, 18 - i, 14) srep(jj, 18 - j, 14) {
    ll ad = (i == ii && j == jj) ? cnt[i][j] * (cnt[i][j] - 1)
                                 : cnt[i][j] * cnt[ii][jj];
    ans += ad;
  }
  ans /= 2;
  cout << ans << '\\n';
  return 0;
}