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

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int N = 100000 + 100;
const db pi = acos(-1.0);
#define lowbit(x) ((x) & (-x))
#define sqr(x) (x) * (x)
#define rep(i, a, b) for (register int i = a; i <= b; i++)
#define per(i, a, b) for (register int i = a; i >= b; i--)
#define go(u, i)                                                               \\
  for (register int i = head[u], v = sq[i].to; i; i = sq[i].nxt, v = sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

inline ll readll() {
  ll x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

int n, g[100][100];

int main() {
  n = read();
  ll ans = 0;
  rep(i, 1, n) {
    double x;
    scanf("%lf", &x);
    ll num = round(x * 1e9);
    // cout << y << endl;
    int c2 = 0, c5 = 0;
    while (num % 2 == 0) {
      c2++;
      num /= 2;
    }
    while (num % 5 == 0) {
      c5++;
      num /= 5;
    }
    // cout << c2 << " " << c5 << endl;
    rep(x, max(18 - c2, 0), 50) rep(y, max(18 - c5, 0), 50) ans += g[x][y];
    g[c2][c5]++;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int N = 100000 + 100;
const db pi = acos(-1.0);
#define lowbit(x) ((x) & (-x))
#define sqr(x) (x) * (x)
#define rep(i, a, b) for (register int i = a; i <= b; i++)
#define per(i, a, b) for (register int i = a; i >= b; i--)
#define go(u, i)                                                               \\
  for (register int i = head[u], v = sq[i].to; i; i = sq[i].nxt, v = sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

inline ll readll() {
  ll x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

int n, g[100][100];

int main() {
  n = read();
  ll ans = 0;
  rep(i, 1, n) {
    double x;
    scanf("%lf", &x);
    ll y = round(x * 1e9);
    // cout << y << endl;
    int c2 = 0, c5 = 0;
    while (y % 2 == 0) {
      c2++;
      y /= 2;
    }
    while (y % 5 == 0) {
      c5++;
      y /= 5;
    }
    // cout << c2 << " " << c5 << endl;
    rep(x, 18 - c2, 50) rep(y, 18 - c5, 50) ans += g[x][y];
    g[c2][c5]++;
  }
  printf("%lld\\n", ans);
  return 0;
}