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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

inline int popcount(ll x) { return __builtin_popcountll(x); }
inline int div2num(ll x) { return __builtin_ctzll(x); }
inline bool bit(ll x, int b) { return (x >> b) & 1; }

template <class T> string to_string(T s);
template <class S, class T> string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T> string to_string(T v) {
  if (v.empty())
    return "{}";
  string ret = "{";
  for (auto x : v)
    ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}

template <class S, class T> string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + ":" + to_string(p.second) + "}";
}
void debug() { cerr << endl; }

template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
  static constexpr size_t buf_size = 1 << 18;
  char buf_in[buf_size], buf_out[buf_size];
  size_t pt_in = 0, pt_out = 0, tail_in = 0;
  char strs[10000 * 4];
  inline size_t num_digits(long long x) {
    if (x >= (long long)1e9) {
      if (x >= (long long)1e18)
        return 19;
      if (x >= (long long)1e17)
        return 18;
      if (x >= (long long)1e16)
        return 17;
      if (x >= (long long)1e15)
        return 16;
      if (x >= (long long)1e14)
        return 15;
      if (x >= (long long)1e13)
        return 14;
      if (x >= (long long)1e12)
        return 13;
      if (x >= (long long)1e11)
        return 12;
      if (x >= (long long)1e10)
        return 11;
      return 10;
    } else {
      if (x >= (long long)1e8)
        return 9;
      if (x >= (long long)1e7)
        return 8;
      if (x >= (long long)1e6)
        return 7;
      if (x >= (long long)1e5)
        return 6;
      if (x >= (long long)1e4)
        return 5;
      if (x >= (long long)1e3)
        return 4;
      if (x >= (long long)1e2)
        return 3;
      if (x >= (long long)1e1)
        return 2;
      return 1;
    }
  }
  IO() {
    load();
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
  ~IO() { flush(); }
  inline void load() {
    memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
    size_t width = tail_in - pt_in;
    tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
    pt_in = 0;
  }
  inline void flush() {
    fwrite(buf_out, 1, pt_out, stdout);
    pt_out = 0;
  }
  inline void read(char &c) { c = buf_in[pt_in++]; }
  template <class T> inline void read(T &x) {
    if (pt_in + 32 > tail_in)
      load();
    char c;
    do {
      read(c);
    } while (c < '0');
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      read(c);
    }
    x = 0;
    while (c >= '0') {
      x = x * 10 + (c & 15);
      read(c);
    }
    if (minus)
      x = -x;
  }
  inline void write(char c) { buf_out[pt_out++] = c; }
  template <class T> inline void write(T x) {
    if (pt_out > buf_size - 32)
      flush();
    if (x < 0) {
      write('-');
      x = -x;
    }
    size_t digits = num_digits(x);
    int i;
    for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
      memcpy(buf_out + i, strs + (x % 10000) * 4, 4);
      x /= 10000;
    }
    memcpy(buf_out + pt_out, strs + x * 4 + (pt_out - i), 4 + i - pt_out);
    pt_out += digits;
  }
  inline void write(const char *s) {
    if (pt_out > buf_size - 32)
      flush();
    for (int i = 0; s[i] != 0; ++i)
      write(s[i]);
  }
  template <class T> inline void writeln(T x) {
    write(x);
    write('\\n');
  }
} io;

int main() {
  int N;
  io.read(N);
  int a = 0, b = 0, c = 0;
  REP(i, N) {
    char ch;
    io.read(ch);
    if (ch == 'A')
      a++;
    else if (ch == 'W')
      b++;
    else if (ch == 'T')
      c++;
    while (ch != '\\n')
      io.read(ch);
    if (io.pt_in + 32 > io.tail_in)
      io.load();
  }
  io.write("AC x ");
  io.writeln(a);
  io.write("WA x ");
  io.writeln(b);
  io.write("TLE x ");
  io.writeln(c);
  io.write("RE x ");
  io.writeln(N - a - b - c);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

inline int popcount(ll x) { return __builtin_popcountll(x); }
inline int div2num(ll x) { return __builtin_ctzll(x); }
inline bool bit(ll x, int b) { return (x >> b) & 1; }

template <class T> string to_string(T s);
template <class S, class T> string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T> string to_string(T v) {
  if (v.empty())
    return "{}";
  string ret = "{";
  for (auto x : v)
    ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}

template <class S, class T> string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + ":" + to_string(p.second) + "}";
}
void debug() { cerr << endl; }

template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
  static constexpr size_t buf_size = 1 << 18;
  char buf_in[buf_size], buf_out[buf_size];
  size_t pt_in = 0, pt_out = 0, tail_in = 0;
  char strs[10000 * 4];
  inline size_t num_digits(long long x) {
    if (x >= (long long)1e9) {
      if (x >= (long long)1e18)
        return 19;
      if (x >= (long long)1e17)
        return 18;
      if (x >= (long long)1e16)
        return 17;
      if (x >= (long long)1e15)
        return 16;
      if (x >= (long long)1e14)
        return 15;
      if (x >= (long long)1e13)
        return 14;
      if (x >= (long long)1e12)
        return 13;
      if (x >= (long long)1e11)
        return 12;
      if (x >= (long long)1e10)
        return 11;
      return 10;
    } else {
      if (x >= (long long)1e8)
        return 9;
      if (x >= (long long)1e7)
        return 8;
      if (x >= (long long)1e6)
        return 7;
      if (x >= (long long)1e5)
        return 6;
      if (x >= (long long)1e4)
        return 5;
      if (x >= (long long)1e3)
        return 4;
      if (x >= (long long)1e2)
        return 3;
      if (x >= (long long)1e1)
        return 2;
      return 1;
    }
  }
  IO() {
    load();
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
  ~IO() { flush(); }
  inline void load() {
    memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
    size_t width = tail_in - pt_in;
    tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
    pt_in = 0;
  }
  inline void flush() {
    fwrite(buf_out, 1, pt_out, stdout);
    pt_out = 0;
  }
  inline void read(char &c) { c = buf_in[pt_in++]; }
  template <class T> inline void read(T &x) {
    if (pt_in + 32 > tail_in)
      load();
    char c;
    do {
      read(c);
    } while (c < '0');
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      read(c);
    }
    x = 0;
    while (c >= '0') {
      x = x * 10 + (c & 15);
      read(c);
    }
    if (minus)
      x = -x;
  }
  inline void write(char c) { buf_out[pt_out++] = c; }
  template <class T> inline void write(T x) {
    if (pt_out > buf_size - 32)
      flush();
    if (x < 0) {
      write('-');
      x = -x;
    }
    size_t digits = num_digits(x);
    int i;
    for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
      memcpy(buf_out + i, strs + (x % 10000) * 4, 4);
      x /= 10000;
    }
    memcpy(buf_out + pt_out, strs + x * 4 + (pt_out - i), 4 + i - pt_out);
    pt_out += digits;
  }
  inline void write(const char *s) {
    if (pt_out > buf_size - 32)
      flush();
    for (int i = 0; s[i] != 0; ++i)
      write(s[i]);
  }
  template <class T> inline void writeln(T x) {
    write(x);
    write('\\n');
  }
} io;

int main() {
  int N;
  io.read(N);
  int a = 0, b = 0, c = 0;
  REP(i, N) {
    char ch;
    io.read(ch);
    if (ch == 'A')
      a++;
    else if (ch == 'W')
      b++;
    else if (ch == 'T')
      c++;
    while (ch != '\\n')
      io.read(ch);
  }
  io.write("AC x ");
  io.writeln(a);
  io.write("WA x ");
  io.writeln(b);
  io.write("TLE x ");
  io.writeln(c);
  io.write("RE x ");
  io.writeln(N - a - b - c);
  return 0;
}