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

// g++ t.cpp -o t && t < p.txt
// d>p.txt&&t<p.txt&&t2<p.txt

#include <algorithm> // みんな大好きソートと二分探索
#include <bitset>
#include <ctime>
#include <functional> // 関数を変数に入れる子
#include <iostream>   // プログラムの耳と口
#include <map>        // setの妹 これまた優秀
#include <queue>      // きゅーちゃん、だいすき
#include <random>     // 乱択さん
#include <set>        // 値の取得・挿入・削除を高速に
#include <string>     // to_string
#include <vector>     // 超有能配列秘書

#define DB cerr << "D" << endl
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ll LINF = 1e18;
const double dINF = 1e18;
const ld ldINF = 1e18;
const double EPS = 1e-6;
template <typename T, typename U, typename O> void caut(T a, U b, O c) {
  cout << "(" << a << "," << b << "," << c << ") ";
}
template <typename T, typename U> void caut(T a, U b) {
  cout << "(" << a << "," << b << ") ";
}
template <typename T> void caut(T a) { cout << "(" << a << ") "; };
using P = pair<ll, ll>;
const ll M = 1e9 + 7;
ll mod_pow(ll x, ll a) {
  ll an = 1;
  while (a > 0) {
    if (a & 1)
      an = an * x % M;
    x = x * x % M;
    a >>= 1;
  }
  return an;
}
void add(ll &x, ll y) {
  x += y;
  x %= M;
};
void mul(ll &x, ll y) {
  x *= y;
  x %= M;
};
template <typename T, typename U> void chmax(T &x, U y) {
  if (x < y)
    x = y;
};
template <typename T, typename U> void chmin(T &x, U y) {
  if (x > y)
    x = y;
}
bool vaild(int x, int y, int hh, int ww) {
  return 0 <= x && x < hh && 0 <= y && y < ww;
}
int keta(ll a) {
  int res = 0;
  while (a > 0)
    res += a % 10, a /= 10;
  return res;
}
const int up[] = {1, -1, 0, 0}, lf[] = {0, 0, 1, -1};

int main() {
  int n;
  cin >> n;
  ll an = 0;
  ll c[61][31];
  fill(c[0], c[61], 0); // 足りるか足りないか +15する

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int m = s.size();
    int p = m - 1;
    ll fs = 0;
    for (int j = 0; j < m; j++) {
      if (s[j] == '.') {
        p = j;
      } else {
        fs = fs * 10 + (s[j] - '0');
      }
    }
    int a2 = p + 1 - m, a5 = a2;
    while (fs % 2 == 0)
      fs /= 2, a2++;
    while (fs % 5 == 0)
      fs /= 5, a5++;
    // cout<<a2<<" "<<a5<<endl;
    a2 += 30;
    a5 += 15;
    for (int j = 0; j < 61; j++) {
      for (int k = 0; k < 31; k++) {
        if (a2 + j - 60 >= 0 && a5 + k - 30 >= 0) {
          an += c[j][k];
        }
      }
    }
    c[a2][a5]++;
  }
  cout << an << endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Error: 0

Fixed submission:

// g++ t.cpp -o t && t < p.txt
// d>p.txt&&t<p.txt&&t2<p.txt

#include <algorithm> // みんな大好きソートと二分探索
#include <bitset>
#include <ctime>
#include <functional> // 関数を変数に入れる子
#include <iostream>   // プログラムの耳と口
#include <map>        // setの妹 これまた優秀
#include <queue>      // きゅーちゃん、だいすき
#include <random>     // 乱択さん
#include <set>        // 値の取得・挿入・削除を高速に
#include <string>     // to_string
#include <vector>     // 超有能配列秘書

#define DB cerr << "D" << endl
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ll LINF = 1e18;
const double dINF = 1e18;
const ld ldINF = 1e18;
const double EPS = 1e-6;
template <typename T, typename U, typename O> void caut(T a, U b, O c) {
  cout << "(" << a << "," << b << "," << c << ") ";
}
template <typename T, typename U> void caut(T a, U b) {
  cout << "(" << a << "," << b << ") ";
}
template <typename T> void caut(T a) { cout << "(" << a << ") "; };
using P = pair<ll, ll>;
const ll M = 1e9 + 7;
ll mod_pow(ll x, ll a) {
  ll an = 1;
  while (a > 0) {
    if (a & 1)
      an = an * x % M;
    x = x * x % M;
    a >>= 1;
  }
  return an;
}
void add(ll &x, ll y) {
  x += y;
  x %= M;
};
void mul(ll &x, ll y) {
  x *= y;
  x %= M;
};
template <typename T, typename U> void chmax(T &x, U y) {
  if (x < y)
    x = y;
};
template <typename T, typename U> void chmin(T &x, U y) {
  if (x > y)
    x = y;
}
bool vaild(int x, int y, int hh, int ww) {
  return 0 <= x && x < hh && 0 <= y && y < ww;
}
int keta(ll a) {
  int res = 0;
  while (a > 0)
    res += a % 10, a /= 10;
  return res;
}
const int up[] = {1, -1, 0, 0}, lf[] = {0, 0, 1, -1};

int main() {
  int n;
  cin >> n;
  ll an = 0, a[16][8];
  fill(a[0], a[16], 0); // ニーズ
  ll b[16][8];
  fill(b[0], b[16], 0); // 供給
  ll c[31][15];
  fill(c[0], c[31], 0); // 足りるか足りないか +15する

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int m = s.size();
    int p = m - 1;
    ll fs = 0;
    for (int j = 0; j < m; j++) {
      if (s[j] == '.') {
        p = j;
      } else {
        fs = fs * 10 + (s[j] - '0');
      }
    }
    int a2 = p + 1 - m, a5 = a2;
    while (fs % 2 == 0)
      fs /= 2, a2++;
    while (fs % 5 == 0)
      fs /= 5, a5++;
    // cout<<a2<<" "<<a5<<endl;
    a2 += 15;
    a5 += 7;
    for (int j = 0; j < 31; j++) {
      for (int k = 0; k < 15; k++) {
        // if (a2 == 19 && a5 == 7) {
        //   cout<<j<<" "<<k<<" "<<a2 + j - 30<<" "<<a5 + k - 14<<"
        //   "<<c[j][k]<<endl;
        // }
        if (a2 + j - 30 >= 0 && a5 + k - 14 >= 0) {
          an += c[j][k];
        }
      }
    }
    c[a2][a5]++;
    /*
    int a2=0;
    if (p == -1) {
      int a2=0, a5=0;
      while(fs % 2 == 0) fs/=2, a2++;
      while(fs % 5 == 0) fs/=5, a5++;
      cout<<a2<<" "<<a5<<endl;
      b[a2][a5]++;
    } else {
      ll sc = stoi(s.substr(p+1,m-p-1));
      if (sc == 0) {
        int a2=0, a5=0;
        while(fs % 2 == 0) fs/=2, a2++;
        while(fs % 5 == 0) fs/=5, a5++;
        cout<<a2<<" "<<a5<<endl;
        b[a2][a5]++;
      } else {
        int b2=m-p-1, b5=b2;
        while(sc % 2 == 0) sc /= 2, b2--;
        while(sc % 5 == 0) sc /= 5, b5--;
        b2 = max(b2, 0); b5 = max(b5, 0);
        if (b2 < 16 && b5 < 8) a[b2][b5]++;
      }
    }*/
  }
  /*
  for(int i=0;i<31;i++) {
    for(int j=0;j<15;j++) {
      cout<<c[i][j]<<" ";
    } cout<<endl;
  }*/
  cout << an << endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest