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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define int long long
// #define debug(x) cout<<#x<<' '<<x<<endl;
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int, int> pii;
int n;
bool inte[200010];
// string l[200010],r[200010];
int lenr[200010];
// int l[200010],r[200010];
int have[210][210]; // 至少i个2，j个5
int have2[210][210][210]; // 小数部分有k位时至少有i个2，j个5的小数有多少
int need2[200010], need5[200010]; // i需要几个2，几个5(小数部分)
int b2[200010], b5[200010];
int chint(string st) {
  int ret = 0;
  for (auto c : st)
    ret = ret * 10 + c - '0';
  return ret;
}
signed main() {
  int ans = 0, cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    string y = "-1";
    char s = getchar();
    if (s == '.') {
      cin >> y;
      while (y.size() && y.back() == '0')
        y.pop_back();
      if (y.empty())
        y = "-1";
      else
        lenr[i] = y.size();
    }
    // l[i]=to_string(x),r[i]=y;
    // cout<<x<<' '<<y<<endl;
    if (y == "-1") { // is integer
      inte[i] = 1;
      cnt++;
      int cur2 = 0, cur5 = 0;
      while (x != 0 && x % 2 == 0)
        x /= 2, cur2++;
      while (x != 0 && x % 5 == 0)
        x /= 5, cur5++;
      have[cur2][cur5]++;
      // have2[cur2][cur5][0]++;
      // cout<<cur2<<' '<<cur5<<endl;
    } else {
      inte[i] = 0;
      need2[i] = lenr[i];
      need5[i] = lenr[i];
      int tp = chint(y);
      int newx = tp;
      while (newx != 0 && newx % 2 == 0)
        newx /= 2, need2[i]--, b2[i]++;
      while (newx != 0 && newx % 5 == 0)
        newx /= 5, need5[i]--, b5[i]++;
      need2[i] = max(0LL, need2[i]);
      need5[i] = max(0LL, need5[i]);
    }
    if (y != "-1") {
      int cur2 = 0, cur5 = 0;
      int yint = chint(y);
      int toall = x * pow(10, lenr[i]) + yint;
      if (toall < 0)
        toall = 0;
      // cout<<yint<<' '<<toall<<endl;
      while (toall != 0 && toall % 2 == 0)
        toall /= 2, cur2++;
      while (toall != 0 && toall % 5 == 0)
        toall /= 5, cur5++;
      have2[cur2][cur5][lenr[i]]++;
      b2[i] = cur2;
      b5[i] = cur5;
      // printf("have2[%lld][%lld][%lld]++\\n",cur2,cur5,lenr[i]);
    }
    // cout<<l[i]<<' '<<r[i]<<endl;
  }
  ans += cnt * (cnt - 1); // int,int
  // cout<<ans<<endl;
  for (int i = 99; i >= 0; i--) // int,double
    for (int j = 99; j >= 0; j--)
      have[i][j] += have[i][j + 1] + have[i + 1][j] - have[i + 1][j + 1];
  for (int i = 99; i >= 0; i--)
    for (int j = 99; j >= 0; j--)
      for (int k = 60; k >= 0; k--)
        have2[i][j][k] += have2[i + 1][j][k];
  for (int i = 99; i >= 0; i--)
    for (int j = 99; j >= 0; j--)
      for (int k = 60; k >= 0; k--)
        have2[i][j][k] += have2[i][j + 1][k];
  // for(int i=99;i>=0;i--)
  // 	for(int j=99;j>=0;j--)
  // 		for(int k=60;k>=0;k--)
  // 			have2[i][j][k]+=have2[i][j][k+1];
  // for(int i=0;i<=10;i++){
  // 	for(int j=0;j<=10;j++)cout<<have[i][j]<<' ';
  // 	puts("");
  // }
  // cout<<have[1][1]<<endl;
  // int nans=0;
  for (int i = 1; i <= n; i++) {
    if (need2[i] < 0)
      need2[i] = 0;
    if (need5[i] < 0)
      need5[i] = 0;
  }
  for (int i = 1; i <= n; i++)
    if (!inte[i]) {
      ans += 2 * have[need2[i]][need5[i]];
    }
  // cout<<ans<<endl;
  // double,double
  // cout<<have2[0][2][1]<<' '<<have2[2][0][1]<<endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 20; j++)
      if (!inte[i]) {
        // ans+=have2[need2[i]+j][need5[i]+j][j];
        // cout<<i<<' '<<j<<' '<<lenr[i]+j-b2[i]<<' '<<lenr[i]+j-b5[i]<<' ';
        ans += have2[max(0LL, lenr[i] + j - b2[i])]
                    [max(0LL, lenr[i] + j - b5[i])][j];
        // debug(have2[max(0LL,lenr[i]+j-b2[i])][max(0LL,lenr[i]+j-b5[i])][j]);
        // cout<<i<<' '<<j<<' '<<need2[i]+j<<' '<<need5[i]+j<<' '<<j<<endl;
      }
  }
  // cout<<ans<<' '<<nans<<endl;
  // ans+=nans/2;
  // cout<<ans<<endl;
  cout << ans / 2 << endl;
  return 0;
}
/*
5
7.5
2.4
17.000000001
17
16.000000000

*/

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define int long long
#define debug(x) cout << #x << ' ' << x << endl;
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int, int> pii;
int n;
bool inte[200010];
// string l[200010],r[200010];
int lenr[200010];
// int l[200010],r[200010];
int have[210][210]; // 至少i个2，j个5
int have2[210][210][210]; // 小数部分有k位时至少有i个2，j个5的小数有多少
int need2[210], need5[210]; // i需要几个2，几个5(小数部分)
int b2[210], b5[210];
int chint(string st) {
  int ret = 0;
  for (auto c : st)
    ret = ret * 10 + c - '0';
  return ret;
}
signed main() {
  int ans = 0, cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    string y = "-1";
    char s = getchar();
    if (s == '.') {
      cin >> y;
      while (y.size() && y.back() == '0')
        y.pop_back();
      if (y.empty())
        y = "-1";
      else
        lenr[i] = y.size();
    }
    // l[i]=to_string(x),r[i]=y;
    // cout<<x<<' '<<y<<endl;
    if (y == "-1") { // is integer
      inte[i] = 1;
      cnt++;
      int cur2 = 0, cur5 = 0;
      while (x != 0 && x % 2 == 0)
        x /= 2, cur2++;
      while (x != 0 && x % 5 == 0)
        x /= 5, cur5++;
      have[cur2][cur5]++;
      // have2[cur2][cur5][0]++;
      // cout<<cur2<<' '<<cur5<<endl;
    } else {
      inte[i] = 0;
      need2[i] = lenr[i];
      need5[i] = lenr[i];
      int tp = chint(y);
      int newx = tp;
      while (newx != 0 && newx % 2 == 0)
        newx /= 2, need2[i]--, b2[i]++;
      while (newx != 0 && newx % 5 == 0)
        newx /= 5, need5[i]--, b5[i]++;
      need2[i] = max(0LL, need2[i]);
      need5[i] = max(0LL, need5[i]);
    }
    if (y != "-1") {
      int cur2 = 0, cur5 = 0;
      int yint = chint(y);
      int toall = x * pow(10, lenr[i]) + yint;
      if (toall < 0)
        toall = 0;
      // cout<<yint<<' '<<toall<<endl;
      while (toall != 0 && toall % 2 == 0)
        toall /= 2, cur2++;
      while (toall != 0 && toall % 5 == 0)
        toall /= 5, cur5++;
      have2[cur2][cur5][lenr[i]]++;
      b2[i] = cur2;
      b5[i] = cur5;
      // printf("have2[%lld][%lld][%lld]++\\n",cur2,cur5,lenr[i]);
    }
    // cout<<l[i]<<' '<<r[i]<<endl;
  }
  ans += cnt * (cnt - 1); // int,int
  // cout<<ans<<endl;
  for (int i = 99; i >= 0; i--) // int,double
    for (int j = 99; j >= 0; j--)
      have[i][j] += have[i][j + 1] + have[i + 1][j] - have[i + 1][j + 1];
  for (int i = 99; i >= 0; i--)
    for (int j = 99; j >= 0; j--)
      for (int k = 60; k >= 0; k--)
        have2[i][j][k] += have2[i + 1][j][k];
  for (int i = 99; i >= 0; i--)
    for (int j = 99; j >= 0; j--)
      for (int k = 60; k >= 0; k--)
        have2[i][j][k] += have2[i][j + 1][k];
  // for(int i=99;i>=0;i--)
  // 	for(int j=99;j>=0;j--)
  // 		for(int k=60;k>=0;k--)
  // 			have2[i][j][k]+=have2[i][j][k+1];
  // for(int i=0;i<=10;i++){
  // 	for(int j=0;j<=10;j++)cout<<have[i][j]<<' ';
  // 	puts("");
  // }
  // cout<<have[1][1]<<endl;
  // int nans=0;
  for (int i = 1; i <= n; i++) {
    if (need2[i] < 0)
      need2[i] = 0;
    if (need5[i] < 0)
      need5[i] = 0;
  }
  for (int i = 1; i <= n; i++)
    if (!inte[i]) {
      ans += 2 * have[need2[i]][need5[i]];
    }
  // cout<<ans<<endl;
  // double,double
  // cout<<have2[0][2][1]<<' '<<have2[2][0][1]<<endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 20; j++)
      if (!inte[i]) {
        // ans+=have2[need2[i]+j][need5[i]+j][j];
        // cout<<i<<' '<<j<<' '<<lenr[i]+j-b2[i]<<' '<<lenr[i]+j-b5[i]<<' ';
        ans += have2[max(0LL, lenr[i] + j - b2[i])]
                    [max(0LL, lenr[i] + j - b5[i])][j];
        // debug(have2[max(0LL,lenr[i]+j-b2[i])][max(0LL,lenr[i]+j-b5[i])][j]);
        // cout<<i<<' '<<j<<' '<<need2[i]+j<<' '<<need5[i]+j<<' '<<j<<endl;
      }
  }
  // cout<<ans<<' '<<nans<<endl;
  // ans+=nans/2;
  // cout<<ans<<endl;
  cout << ans / 2 << endl;
  return 0;
}
/*
5
7.5
2.4
17.000000001
17
16.000000000

*/