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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
typedef pair<int, int> P;
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void coY() { cout << "Yes" << endl; }
void coN() { cout << "No" << endl; }

// Write From this Line

// const ll mod = 1e9+7;
// const ll mod = 998244353;
int main() {
  // 積としてありえるのは、1,2,3,...,10^8通り。
  //  全部10^9して考えても良いかも。そうすれば、2の数,5の数の和が18以上のやつだけ考えれば良い。1
  ll n;
  cin >> n;
  vector<vector<ll>> mas(21, vector<ll>(21, 0));
  ll ans = 0;

  rep(i, n) {
    string s;
    cin >> s;
    vector<int> neko(14, 0);
    int ind = s.size();
    rep(j, s.size()) {
      if (s[j] == '.') {
        ind = j;
      }
    }
    int k = 5;
    if (ind == -1) {
      // 整数だから、neko[5]より後は全部0
      ;
    } else {
      for (int j = ind + 1; j < s.size(); j++) {
        neko[k] = s[j] - '0';
        k++;
      }
    }
    k = 4;
    for (int j = ind - 1; j >= 0; j--) {
      neko[k] = s[j] - '0';
      k--;
    }
    ll tmp = 0;
    ll ten = 1;
    rep(j, 14) {
      tmp += neko[13 - j] * ten;
      ten *= 10;
    }
    int ni = 0;
    int go = 0;
    while (tmp % 2 == 0) {
      ni++;
      tmp /= 2;
    }
    while (tmp % 5 == 0) {
      go++;
      tmp /= 5;
    }
    ni = min(18, ni);
    go = min(18, go);
    int needt = 18 - ni;
    int needg = 18 - go;
    for (int N = needt; N <= 18; N++) {
      for (int G = needg; G <= 18; G++) {
        ans += mas[N][G];
      }
    }
    mas[ni][go]++;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
typedef pair<int, int> P;
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void coY() { cout << "Yes" << endl; }
void coN() { cout << "No" << endl; }

// Write From this Line

// const ll mod = 1e9+7;
// const ll mod = 998244353;
int main() {
  // 積としてありえるのは、1,2,3,...,10^8通り。
  //  全部10^9して考えても良いかも。そうすれば、2の数,5の数の和が18以上のやつだけ考えれば良い。1
  ll n;
  cin >> n;
  vector<vector<ll>> mas(21, vector<ll>(21, 0));
  ll ans = 0;

  rep(i, n) {
    double s;
    cin >> s;
    ll tmp = s * 1e10;
    int ni = 0;
    int go = 0;
    while (tmp % 2 == 0) {
      ni++;
      tmp /= 2;
    }
    while (tmp % 5 == 0) {
      go++;
      tmp /= 5;
    }
    int needt = 20 - ni;
    int needg = 20 - go;
    for (int N = needt; N <= 20; N++) {
      for (int G = needg; G <= 20; G++) {
        ans += mas[N][G];
      }
    }
    mas[ni][go]++;
  }
  cout << ans << endl;
}