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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
  int N;
  cin >> N;
  vl A(N);
  vector<vl> A25(19);
  rep(i, 19) A25[i].resize(19, 0);
  rep(i, N) {
    string Atmp;
    cin >> Atmp;
    int n = Atmp.length();
    bool I = true;
    rep(i, n) {
      if (Atmp[i] == '.')
        I = 0;
    }
    if (I) {
      Atmp.push_back('.');
      Atmp.push_back('0');
    }
    n = Atmp.length();
    int dot = n;
    rep(i, n) {
      if (Atmp[i] == '.')
        dot = i;
    }
    rep(i, dot - n + 10) Atmp.push_back('0');
    n = Atmp.length();
    string a;
    rep(i, n) {
      if (Atmp[i] != '.')
        a.push_back(Atmp[i]);
    }
    A[i] = stoll(a);
    ll AA = A[i];
    ll A2 = 0, A5 = 0;
    while (1) {
      if (A[i] % 2 != 0)
        break;
      A2++;
      A[i] /= 2;
    }
    while (1) {
      if (A[i] % 5 != 0)
        break;
      A5++;
      A[i] /= 5;
    }
    A2 = min(A2, 18LL);
    A5 = min(A5, 18LL);
    A25[A2][A5]++;
    A[i] = AA;
  }
  ll ans = 0;
  rep(i, N) {
    ll A2 = 0, A5 = 0;
    while (1) {
      if (A[i] % 2 != 0)
        break;
      A2++;
      A[i] /= 2;
    }
    while (1) {
      if (A[i] % 5 != 0)
        break;
      A5++;
      A[i] /= 5;
    }
    A2 = min(A2, 18LL);
    A5 = min(A5, 18LL);
    if (A2 >= 9 && A5 >= 9)
      ans--;
    rep(a, 19) {
      rep(b, 19) {
        if (a + A2 >= 18 && b + A5 >= 18)
          ans += A25[a][b];
      }
    }
  }
  ans /= 2;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
  int N;
  cin >> N;
  vl A(N);
  vector<vl> A25(19);
  rep(i, 18) A25[i].resize(19, 0);
  rep(i, N) {
    string Atmp;
    cin >> Atmp;
    int n = Atmp.length();
    bool I = true;
    rep(i, n) {
      if (Atmp[i] == '.')
        I = 0;
    }
    if (I) {
      Atmp.push_back('.');
      Atmp.push_back('0');
    }
    n = Atmp.length();
    int dot = n;
    rep(i, n) {
      if (Atmp[i] == '.')
        dot = i;
    }
    rep(i, dot - n + 10) Atmp.push_back('0');
    n = Atmp.length();
    string a;
    rep(i, n) {
      if (Atmp[i] != '.')
        a.push_back(Atmp[i]);
    }
    A[i] = stoll(a);
    ll AA = A[i];
    ll A2 = 0, A5 = 0;
    while (1) {
      if (A[i] % 2 != 0)
        break;
      A2++;
      A[i] /= 2;
    }
    while (1) {
      if (A[i] % 5 != 0)
        break;
      A5++;
      A[i] /= 5;
    }
    A2 = min(A2, 18LL);
    A5 = min(A5, 18LL);
    A25[A2][A5]++;
    A[i] = AA;
  }
  ll ans = 0;
  rep(i, N) {
    ll A2 = 0, A5 = 0;
    while (1) {
      if (A[i] % 2 != 0)
        break;
      A2++;
      A[i] /= 2;
    }
    while (1) {
      if (A[i] % 5 != 0)
        break;
      A5++;
      A[i] /= 5;
    }
    A2 = min(A2, 18LL);
    A5 = min(A5, 18LL);
    if (A2 >= 9 && A5 >= 9)
      ans--;
    rep(a, 18) {
      rep(b, 18) {
        if (a + A2 >= 18 && b + A5 >= 18)
          ans += A25[a][b];
      }
    }
  }
  ans /= 2;

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