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

#include <bits/stdc++.h>

#define endl '\\n'
#define fi first
#define se second
#define MOD(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, n) for (int i = 0; i < n; i++)
#define forr(i, a, b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 105;
int n, cn[MX][MX][MX], mx1, mx2, mx3;
ll res, s, a[200005];

int count(ll n, int k) {
  ll res = 0;
  while (n % k == 0) {
    n /= k;
    res++;
  }
  return res;
}

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

  cin >> n;

  forn(i, n) {
    string in;
    cin >> in;

    int f = 0;
    forn(j, in.size()) f |= in[j] == '.';

    if (f) {
      f = 0;
      for (int j = (int)in.size() - 1; j >= 0 && in[j] != '.'; j--)
        f++;
    }

    forn(j, in.size()) if (in[j] != '.') {
      a[i] *= 10;
      a[i] += in[j] - '0';
    }

    int two = count(a[i], 2);
    int five = count(a[i], 5);

    cn[f][two][five]++;

    mx1 = max(mx1, f);
    mx2 = max(mx2, two);
    mx3 = max(mx3, five);
  }

  forn(i, mx1 + 1) forn(j, mx2 + 1) forn(k, mx3 + 1) {
    forn(a, mx1 + 1) forn(b, mx2 + 1) forn(c, mx3 + 1) {
      if (i + a <= min(j + b, k + c)) {
        if (a != i || b != j || c != k)
          res += 1ll * cn[i][j][k] * cn[a][b][c];
        else
          res += 1ll * cn[i][j][k] * (cn[i][j][k] - 1);
      }
    }
  }

  cout << res / 2 << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define endl '\\n'
#define fi first
#define se second
#define MOD(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, n) for (int i = 0; i < n; i++)
#define forr(i, a, b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 55;
int n, cn[MX][MX][MX], mx1, mx2, mx3;
ll res, s, a[MX];

int count(ll n, int k) {
  ll res = 0;
  while (n % k == 0) {
    n /= k;
    res++;
  }
  return res;
}

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

  cin >> n;

  forn(i, n) {
    string in;
    cin >> in;

    int f = 0;
    forn(j, in.size()) f |= in[j] == '.';

    if (f) {
      f = 0;
      for (int j = (int)in.size() - 1; j >= 0 && in[j] != '.'; j--)
        f++;
    }

    forn(j, in.size()) if (in[j] != '.') {
      a[i] *= 10;
      a[i] += in[j] - '0';
    }

    int two = count(a[i], 2);
    int five = count(a[i], 5);

    cn[f][two][five]++;

    mx1 = max(mx1, f);
    mx2 = max(mx2, two);
    mx3 = max(mx3, five);
  }

  forn(i, mx1 + 1) forn(j, mx2 + 1) forn(k, mx3 + 1) {
    forn(a, mx1 + 1) forn(b, mx2 + 1) forn(c, mx3 + 1) {
      if (i + a <= min(j + b, k + c)) {
        if (a != i || b != j || c != k)
          res += 1ll * cn[i][j][k] * cn[a][b][c];
        else
          res += 1ll * cn[i][j][k] * (cn[i][j][k] - 1);
      }
    }
  }

  cout << res / 2 << endl;

  return 0;
}