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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...)                                             \\
  for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...)                                          \\
  for (int i = (b - 1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef long double ld;

template <class T> map<T, int> prime_factor(T n) {
  map<T, int> ret;
  for (T i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll f(char *s) {
  int n = strlen(s);
  ll ret;
  sscanf(s, "%lld", &ret);
  while (n < 9) {
    ret *= 10;
    n++;
  }
  return ret;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<P> a(n);
  rep(i, n) {
    // char buf[100];
    string buf;
    // scanf("%s", buf);
    cin >> buf;
    eprintf("%s\\n", buf.c_str());
    fflush(stderr);
    bool pe = false;
    // rep (j, strlen(buf)) eprintf("%02d ", buf[j]);
    rep(j, buf.size()) if (buf[j] == '.') pe = true;
    if (!pe) {
      sscanf(buf.c_str(), "%lld", &a[i].first);
    } else {
      char buf2[100];
      sscanf(buf.c_str(), "%lld.%s", &a[i].first, buf2);
      a[i].second = f(buf2);
    }
  }
  eprintf("#\\n");
  fflush(stderr);
  vector<ll> k(n);
  rep(i, n) k[i] = a[i].first * 1000000000 + a[i].second;
  vector<P> fa(n);
  rep(i, n) {
    eprintf("%lld\\n", k[i]);
    fflush(stderr);
    while (k[i] % 2 == 0) {
      fa[i].first++;
      k[i] /= 2;
    }
    while (k[i] % 5 == 0) {
      fa[i].second++;
      k[i] /= 5;
    }
  }
  eprintf("a");
  fflush(stderr);
  int MAX = 145;
  vector<vector<ll>> b(MAX, vector<ll>(MAX));
  rep(i, n) b[fa[i].first][fa[i].second]++;
  // rep (i, 15) {
  //     rep (j, 15) eprintf("%2lld ", b[i][j]); eprintf("\\n");
  // }
  reprev(i, MAX) {
    reprev(j, MAX) {
      if (i > 0)
        b[i - 1][j] += b[i][j];
    }
  }
  reprev(i, MAX) {
    reprev(j, MAX) {
      if (j > 0)
        b[i][j - 1] += b[i][j];
    }
  }
  // rep (i, 15) {
  //     rep (j, 15) eprintf("%2lld ", b[i][j]); eprintf("\\n");
  // }
  eprintf("b");
  fflush(stderr);
  ll ans = 0;
  rep(i, n) {
    ans += b[max(0LL, 18 - fa[i].first)][max(0LL, 18 - fa[i].second)];
    if (2 * fa[i].first >= 18 && 2 * fa[i].second >= 18)
      ans--;
    // eprintf("%d %lld %lld %lld %d\\n", i, fa[i].first, fa[i].second,
    // b[max(0LL, 18 - fa[i].first)][max(0LL, 18 - fa[i].second)], 2 *
    // fa[i].first >= 18 && 2 * fa[i].second >= 18);
  }
  cout << ans / 2 << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...)                                             \\
  for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...)                                          \\
  for (int i = (b - 1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef long double ld;

template <class T> map<T, int> prime_factor(T n) {
  map<T, int> ret;
  for (T i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll f(char *s) {
  int n = strlen(s);
  ll ret;
  sscanf(s, "%lld", &ret);
  while (n < 9) {
    ret *= 10;
    n++;
  }
  return ret;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<P> a(n);
  rep(i, n) {
    char buf[100];
    // scanf("%s", buf);
    cin >> buf;
    eprintf("%s\\n", buf);
    fflush(stderr);
    bool pe = false;
    // rep (j, strlen(buf)) eprintf("%02d ", buf[j]);
    rep(j, strlen(buf)) if (buf[j] == '.') pe = true;
    if (!pe) {
      sscanf(buf, "%lld", &a[i].first);
    } else {
      char buf2[100];
      sscanf(buf, "%lld.%s", &a[i].first, buf2);
      a[i].second = f(buf2);
    }
  }
  eprintf("#\\n");
  fflush(stderr);
  vector<ll> k(n);
  rep(i, n) k[i] = a[i].first * 1000000000 + a[i].second;
  vector<P> fa(n);
  rep(i, n) {
    eprintf("%lld\\n", k[i]);
    fflush(stderr);
    while (k[i] % 2 == 0) {
      fa[i].first++;
      k[i] /= 2;
    }
    while (k[i] % 5 == 0) {
      fa[i].second++;
      k[i] /= 5;
    }
  }
  eprintf("a");
  fflush(stderr);
  vector<vector<ll>> b(31, vector<ll>(31));
  rep(i, n) b[fa[i].first][fa[i].second]++;
  rep(i, 15) {
    rep(j, 15) eprintf("%2d ", b[i][j]);
    eprintf("\\n");
  }
  reprev(i, 31) {
    reprev(j, 31) {
      if (i > 0)
        b[i - 1][j] += b[i][j];
    }
  }
  reprev(i, 31) {
    reprev(j, 31) {
      if (j > 0)
        b[i][j - 1] += b[i][j];
    }
  }
  rep(i, 15) {
    rep(j, 15) eprintf("%2d ", b[i][j]);
    eprintf("\\n");
  }
  eprintf("b");
  fflush(stderr);
  ll ans = 0;
  rep(i, n) {
    ans += b[max(0LL, 18 - fa[i].first)][max(0LL, 18 - fa[i].second)];
    if (2 * fa[i].first >= 18 && 2 * fa[i].second >= 18)
      ans--;
    eprintf("%d %d %d %d %d\\n", i, fa[i].first, fa[i].second,
            b[max(0LL, 18 - fa[i].first)][max(0LL, 18 - fa[i].second)],
            2 * fa[i].first >= 18 && 2 * fa[i].second >= 18);
  }
  cout << ans / 2 << "\\n";
  return 0;
}