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;

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 + 10; j++)
      for (int k = 0; k <= w5 - p + 10; k++)
        res += b[j][k];
    ++b[p - w2 + 10][p - w5 + 10];
    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;
}