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

#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod = 1000000007;

int func(LL n, LL d) {
  int c = 0;
  while (n != 0) {
    if (n % d == 0) {
      c++;
      n /= d;
    } else {
      break;
    }
  }
  return c;
}

pair<int, int> parse(string s) {
  LL nm = 0, c = 1000 * 1000 * 1000, f = 0, ln = s.length();
  FOR(i, 0, ln) {
    if (s[i] == '.') {
      f = 1;
    } else {
      nm *= 10;
      nm += s[i] - '0';
      if (f) {
        c /= 10;
      }
    }
  }
  nm *= c;
  // cerr<<"nm:"<<nm<<endl;
  return make_pair(func(nm, 2), func(nm, 5));
}

int main() {
  int n;
  cin >> n;
  vii v(25, vi(25, 0));
  vector<pii> vp(n);
  FOR(i, 0, n) {
    string s;
    cin >> s;
    auto p = parse(s);
    // cerr<<"**"<<p.ST<<" "<<p.ND<<"**"<<endl;
    v[min(p.ST, 22)][min(p.ND, 22)]++;
    vp[i] = p;
  }

  LL ans = 0;
  FOR(i, 0, n) {
    int c2 = vp[i].ST;
    int c5 = vp[i].ND;
    int r2 = max(18 - c2, 0);
    int r5 = max(18 - c5, 0);
    if (r2 <= c2 && r5 <= c5) {
      ans--;
    }
    FOR(i, r2, 23) {
      FOR(j, r5, 23) { ans += v[i][j]; }
    }
  }
  cout << ans / 2 << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod = 1000000007;

int func(LL n, LL d) {
  int c = 0;
  while (n != 0) {
    if (n % d == 0) {
      c++;
      n /= d;
    } else {
      break;
    }
  }
  return c;
}

pair<int, int> parse(string s) {
  LL nm = 0, c = 1000 * 1000 * 1000, f = 0, ln = s.length();
  FOR(i, 0, ln) {
    if (s[i] == '.') {
      f = 1;
    } else {
      nm *= 10;
      nm += s[i] - '0';
      if (f) {
        c /= 10;
      }
    }
  }
  nm *= c;
  // cerr<<"nm:"<<nm<<endl;
  return make_pair(func(nm, 2), func(nm, 5));
}

int main() {
  int n;
  cin >> n;
  vii v(25, vi(25, 0));
  vector<pii> vp(n);
  FOR(i, 0, n) {
    string s;
    cin >> s;
    auto p = parse(s);
    // cerr<<"**"<<p.ST<<" "<<p.ND<<"**"<<endl;
    v[min(p.ST, 22)][min(p.ND, 22)] = 1;
    vp[i] = p;
  }

  LL ans = 0;
  FOR(i, 0, n) {
    int c2 = vp[i].ST;
    int c5 = vp[i].ND;
    int r2 = 18 - c2;
    int r5 = 18 - c5;
    if (r2 <= c2 && r5 <= c5) {
      ans--;
    }
    FOR(i, r2, 22) {
      FOR(j, r5, 22) { ans += v[i][j]; }
    }
  }
  cout << ans << endl;
}