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

#include <bits/stdc++.h>

using namespace std;

#define lli long long
#define ld long double
#define mod 1000000007
#define set(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define mp make_pair
#define pll pair<lli, lli>
#define endl '\\n'

const double PI = acos(-1);
const double epsilon = 1e-10; // floating point precision

class rational {
public:
  lli p, q;
  rational(string &s) {
    q = 1;
    p = 0;
    bool flag = false;
    for (int i = 0; i < s.length(); i++) {
      if (flag) {
        q *= 10;
      }
      if (s[i] == '.') {
        flag = true;
      } else {
        p = p * 10 + (lli)(s[i] - '0');
      }
    }
    lli gcd = __gcd(p, q);
    p /= gcd;
    q /= gcd;
  }
};

lli ct[51][16][51][16];

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n;
  cin >> n;
  vector<string> v(n);
  memset(ct, 0, sizeof ct);
  lli ans = 0ll;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    rational r(v[i]);
    lli u2 = 0, u5 = 0;
    lli d2 = 0, d5 = 0;
    lli p = r.p;
    lli q = r.q;
    while (p % 2 == 0) {
      p /= 2;
      u2++;
    }
    while (p % 5 == 0) {
      p /= 5;
      u5++;
    }
    while (q % 2 == 0) {
      q /= 2;
      d2++;
    }
    while (q % 5 == 0) {
      q /= 5;
      d5++;
    }
    lli num2 = max(0ll, u2 - d2), num5 = max(0ll, u5 - d5);
    lli dem2 = max(0ll, d2 - u2), dem5 = max(0ll, d5 - u5);
    lli res = 0ll;
    for (auto ii = dem2; ii < 51; ii++) {
      for (auto jj = dem5; jj < 16; jj++) {
        for (auto kk = num2; kk >= 0; kk--) {
          for (auto ll = num5; ll >= 0; ll--) {
            res += ct[ii][jj][kk][ll];
          }
        }
      }
    }
    ans += res;
    ct[num2][num5][dem2][dem5]++;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define lli long long
#define ld long double
#define mod 1000000007
#define set(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define mp make_pair
#define pll pair<lli, lli>
#define endl '\\n'

const double PI = acos(-1);
const double epsilon = 1e-10; // floating point precision

class rational {
public:
  lli p, q;
  rational(string &s) {
    q = 1;
    p = 0;
    bool flag = false;
    for (int i = 0; i < s.length(); i++) {
      if (flag) {
        q *= 10;
      }
      if (s[i] == '.') {
        flag = true;
      } else {
        p = p * 10 + (lli)(s[i] - '0');
      }
    }
    lli gcd = __gcd(p, q);
    p /= gcd;
    q /= gcd;
  }
};

lli ct[16][16][16][16];

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n;
  cin >> n;
  vector<string> v(n);
  memset(ct, 0, sizeof ct);
  lli ans = 0ll;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    rational r(v[i]);
    lli u2 = 0, u5 = 0;
    lli d2 = 0, d5 = 0;
    lli p = r.p;
    lli q = r.q;
    while (p % 2 == 0) {
      p /= 2;
      u2++;
    }
    while (p % 5 == 0) {
      p /= 5;
      u5++;
    }
    while (q % 2 == 0) {
      q /= 2;
      d2++;
    }
    while (q % 5 == 0) {
      q /= 5;
      d5++;
    }
    lli num2 = max(0ll, u2 - d2), num5 = max(0ll, u5 - d5);
    lli dem2 = max(0ll, d2 - u2), dem5 = max(0ll, d5 - u5);
    lli res = 0ll;
    for (auto ii = dem2; ii < 16; ii++) {
      for (auto jj = dem5; jj < 16; jj++) {
        for (auto kk = num2; kk >= 0; kk--) {
          for (auto ll = num5; ll >= 0; ll--) {
            res += ct[ii][jj][kk][ll];
          }
        }
      }
    }
    ans += res;
    ct[num2][num5][dem2][dem5]++;
  }
  cout << ans << endl;
  return 0;
}