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

#include <bits/stdc++.h>
using namespace std;

template <typename T> inline T read() {
  T x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -f;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c - 48);
    c = getchar();
  }
  return x * f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf = 1e9 + 1e7, MAXN = 2e5 + 1e1;
const double eps = 1e-10;

struct Node {
  int w2, w5, p;
};

Node a[MAXN << 1];
int b[3100][3100], n;
lint ans = 0;

void Read(int id) {
  int x = 0, f = 1, X = 0, F = 1, cnt = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -f;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c - 48);
    c = getchar();
  }
  if (c == '.') {
    while (!isdigit(c)) {
      if (c == '-')
        F = -F;
      c = getchar();
    }
    while (isdigit(c)) {
      X = (X << 3) + (X << 1) + (c - 48);
      ++cnt;
      c = getchar();
    }
  }
  lint k3 = X * F;
  if (k3 == 0)
    cnt = 0;
  while ((k3) && (k3 % 10 == 0))
    k3 /= 10, --cnt;
  lint k1 = x * f;
  a[id].p = cnt;
  while (cnt--)
    k1 *= 10;
  lint k2 = k1 + k3;
  while ((k2) && (k2 % 2 == 0))
    ++a[id].w2, k2 /= 2;
  while ((k2) && (k2 % 5 == 0))
    ++a[id].w5, k2 /= 5;
  return;
}

int main(void) {

  // freopen("testdata.in","r",stdin);
  // freopen("testdata.out","w",stdout);

  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    Read(i);
  // for(int i=1;i<=n;i++) printf("%d %d %d\\n",a[i].w2,a[i].w5,a[i].p);
  for (int i = 1; i <= n; i++) {
    lint res = 0;
    int w2 = a[i].w2, w5 = a[i].w5, p = a[i].p;
    for (int j = 0; j <= w2 - p + 48; j++)
      for (int k = 0; k <= w5 - p + 48; k++)
        res += b[j][k];
    ++b[p - w2 + 48][p - w5 + 48];
    ans += res;
    // printf("%lld ",res);
    // printf("%d %d\\n",max(a[i].p-a[i].w2,0),max(a[i].p-a[i].w5,0));
  }
  printf("%lld\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
double a[maxn];
int p[maxn], ans;
bool pd(double x) {
  if (((double)((int)x)) == x)
    return true;
  return false;
}
void doit1(double x) {
  int k = (int)x, len = 0;
  while (k) {
    k >>= 1;
    ++len;
  }
  p[len]++;
}
void doit2(double x) {
  int now = 2, k = 1;
  while (now <= 10000) {
    if (pd(x * now))
      ans += p[k];
    now <<= 1;
    ++k;
  }
  return;
}
signed main() {
  // file(a);
  int sum = 0;
  n = read();
  rep(i, 1, n) {
    scanf("%lf", &a[i]);
    if (pd(a[i]))
      ++sum, doit1(a[i]);
  }
  int k = 1;
  rep(i, max(sum - 1, 3ll), sum) k = 1ll * i * k;
  rep(i, 2, min(sum - 2, 2ll)) k /= i;
  ans += k;
  rep(i, 1, n) if (!pd(a[i])) doit2(a[i]);
  printf("%lld\\n", ans);

  return 0;
}