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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
struct kazu {
  ll two;
  ll five;
};
int main() {
  ll n;
  cin >> n;
  ll res = 0;
  vector<pair<ll, kazu>> a(n);
  for (int i = 0; i < n; i++) {
    string ins;
    cin >> ins;
    a[i].second = {0, 0};

    ll mul = 0;
    /*while(1){
      ll memo = (ll)in;
      if((double)memo != in)in *= 10;
      else{
        break;
      }
      mul++;
    }
    cout << (ll)in << endl;*/
    // string ins = to_string(in);
    ll point = -1;
    for (int j = 0; j < (int)ins.size(); j++) {
      if (ins[j] == '.')
        point = j;
    }
    ll eraselast = 1000;
    ll erasek = 0;
    if (point != -1) {
      for (int j = (int)ins.size() - 1; j >= point; j--) {
        // cout << ins[j] << endl;
        if (ins[j] == '0')
          eraselast = j, erasek++;
        else {
          break;
        }
      }
      if (erasek > 0)
        ins.erase(eraselast, erasek); // 語尾の0を削除
      // cout << ins << endl;
      for (int j = (int)ins.size() - 1; j >= 0; j--) {
        if (ins[j] != '.')
          mul++; // 10の何乗倍するか確かめるため
        else {
          ins.erase(j, 1);
          break;
        }
      }
      if (mul == 0)
        res--;
    } else
      res--; // もともと整数の時1つ多く数えられてしまうので引く

    // cout << ins << endl;//最終形,整数になっているはず
    ll inl = stoll(ins);
    // cout << "!" << " " << to_string(in) << endl;

    a[i].first = mul; // 何桁上げるか

    // ll inc = (ll)in;
    while (1) {
      if (inl % 2 != 0)
        break;
      a[i].second.two++;
      inl /= 2;
    }
    while (1) {
      if (inl % 5 != 0)
        break;
      a[i].second.five++;
      inl /= 5;
    }
    // cout << 2 << endl;
    // cout << ins << " " << a[i].second.two << " " << a[i].second.five << endl;

    a[i].second.two -= a[i].first;
    a[i].second.five -= a[i].first;
    /*while(1){
      //if(a[i].second.two <= 0 || a[i].second.five <= 0)break;
      if(a[i].first <= 0)break;
      a[i].first--;
      a[i].second.two--;
      a[i].second.five--;
    }*/

    // cout << ins << " " << a[i].second.two << " " << a[i].second.five << endl;
  }

  vector<vector<ll>> sum(100, vector<ll>(100)); // それぞれ+50されてる
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 100; j++)
      sum[i][j] = 0;
  for (int i = 0; i < n; i++) {
    sum[a[i].second.two + 50][a[i].second.five + 50]++;
  }

  for (int i = 99; i >= 0; i--) {
    for (int j = 99; j >= 0; j--) {
      if (i == 99 && j == 99)
        continue;
      if (j != 99)
        sum[i][j] += sum[i][j + 1];
      if (i != 99)
        sum[i][j] += sum[i + 1][j];
      if (i != 99 && j != 99)
        sum[i][j] -= sum[i + 1][j + 1];
    }
  }

  /*for(int i = 0;i < 40;i++){
    for(int j = 0;j < 40;j++)cout << sum[i][j] << " ";
    cout << endl;
  }*/

  for (int i = 0; i < n; i++) {
    // cout << i << " " << sum[a[i].second.two * -1 + 50][a[i].second.five * -1
    // + 50] << endl; cout << sum[a[i].second.two * -1 + 20][a[i].second.five *
    // -1 + 20];
    res += sum[a[i].second.two * -1 + 50][a[i].second.five * -1 + 50];
  }
  // cout << res << endl;
  res /= 2; // 相互なのでわる2
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
struct kazu {
  ll two;
  ll five;
};
int main() {
  ll n;
  cin >> n;
  ll res = 0;
  vector<pair<ll, kazu>> a(n);
  for (int i = 0; i < n; i++) {
    string ins;
    cin >> ins;
    a[i].second = {0, 0};

    ll mul = 0;
    /*while(1){
      ll memo = (ll)in;
      if((double)memo != in)in *= 10;
      else{
        break;
      }
      mul++;
    }
    cout << (ll)in << endl;*/
    // string ins = to_string(in);
    ll point = -1;
    for (int j = 0; j < (int)ins.size(); j++) {
      if (ins[j] == '.')
        point = j;
    }
    ll eraselast = 1000;
    ll erasek = 0;
    if (point != -1) {
      for (int j = (int)ins.size() - 1; j >= point; j--) {
        // cout << ins[j] << endl;
        if (ins[j] == '0')
          eraselast = j, erasek++;
        else {
          break;
        }
      }
      if (erasek > 0)
        ins.erase(eraselast, erasek); // 語尾の0を削除
      // cout << ins << endl;
      for (int j = (int)ins.size() - 1; j >= 0; j--) {
        if (ins[j] != '.')
          mul++; // 10の何乗倍するか確かめるため
        else {
          ins.erase(j, 1);
          break;
        }
      }
      if (mul == 0)
        res--;
    } else
      res--; // もともと整数の時1つ多く数えられてしまうので引く

    // cout << ins << endl;//最終形,整数になっているはず
    ll inl = stoll(ins);
    // cout << "!" << " " << to_string(in) << endl;

    a[i].first = mul; // 何桁上げるか

    // ll inc = (ll)in;
    while (1) {
      if (inl % 2 != 0)
        break;
      a[i].second.two++;
      inl /= 2;
    }
    while (1) {
      if (inl % 5 != 0)
        break;
      a[i].second.five++;
      inl /= 5;
    }
    // cout << 2 << endl;
    // cout << ins << " " << a[i].second.two << " " << a[i].second.five << endl;

    a[i].second.two -= a[i].first;
    a[i].second.five -= a[i].first;
    /*while(1){
      //if(a[i].second.two <= 0 || a[i].second.five <= 0)break;
      if(a[i].first <= 0)break;
      a[i].first--;
      a[i].second.two--;
      a[i].second.five--;
    }*/

    // cout << ins << " " << a[i].second.two << " " << a[i].second.five << endl;
  }

  vector<vector<ll>> sum(40, vector<ll>(40)); // それぞれ+20されてる
  for (int i = 0; i < 40; i++)
    for (int j = 0; j < 40; j++)
      sum[i][j] = 0;
  for (int i = 0; i < n; i++) {
    sum[a[i].second.two + 20][a[i].second.five + 20]++;
  }

  for (int i = 39; i >= 0; i--) {
    for (int j = 39; j >= 0; j--) {
      if (i == 39 && j == 39)
        continue;
      if (j != 39)
        sum[i][j] += sum[i][j + 1];
      if (i != 39)
        sum[i][j] += sum[i + 1][j];
      if (i != 39 && j != 39)
        sum[i][j] -= sum[i + 1][j + 1];
    }
  }

  /*for(int i = 0;i < 40;i++){
    for(int j = 0;j < 40;j++)cout << sum[i][j] << " ";
    cout << endl;
  }*/

  for (int i = 0; i < n; i++) {
    // cout << i << " " << sum[a[i].second.two * -1 + 20][a[i].second.five * -1
    // + 20] << endl; cout << sum[a[i].second.two * -1 + 20][a[i].second.five *
    // -1 + 20];
    res += sum[a[i].second.two * -1 + 20][a[i].second.five * -1 + 20];
  }
  // cout << res << endl;
  res /= 2; // 相互なのでわる2
  cout << res << endl;
}