alexjercan/bugnet huggingface dataset:
Problem p00102 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int N;

  while (cin >> N && N != 0) {
    int dataset[11][11] = {0};
    for (int i = 0; i != N; ++i) {
      for (int j = 0; j != N; ++j) {
        cin >> dataset[i][j];
      }
    }

    for (int i = 0; i != N; ++i) {
      for (int j = 0; j != N; ++j) {
        dataset[i][N] += dataset[i][j];
      }
    }

    for (int i = 0; i <= N; ++i) {
      for (int j = 0; j != N; ++j) {
        dataset[N][i] += dataset[j][i];
      }
    }

    for (int i = 0; i != N + 1; ++i) {
      for (int j = 0; j != N + 1; ++j) {
        cout << setw(5) << dataset[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int N;

  while (cin >> N && N != 0) {
    int dataset[N + 1][N + 1];
    for (int i = 0; i != N; ++i) {
      for (int j = 0; j != N; ++j) {
        cin >> dataset[i][j];
      }
    }

    for (int i = 0; i != N; ++i) {
      int total = 0;
      for (int j = 0; j != N; ++j) {
        total += dataset[i][j];
      }
      dataset[i][4] = total;
    }

    for (int i = 0; i != N; ++i) {
      int total = 0;
      for (int j = 0; j != N; ++j) {
        total += dataset[j][i];
      }
      dataset[4][i] = total;
    }

    int ans = 0;
    for (int i = 0; i != N; ++i) {
      ans += dataset[4][i] + dataset[i][4];
    }
    dataset[4][4] = ans;

    for (int i = 0; i != N + 1; ++i) {
      for (int j = 0; j != N + 1; ++j) {
        cout << setw(5) << dataset[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00102 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

#define REP(i, m, n)                                                           \\
  for (int i = static_cast<int>(m); i < static_cast<int>(n); ++i)

int main() {

  while (true) {
    int n;
    std::cin >> n;
    if (n == 0)
      break;

    VVI vvi;

    REP(i, 0, n) {
      vvi.push_back(vector<int>());
      int sum = 0;

      REP(j, 0, n) {
        int in;
        std::cin >> in;
        vvi[i].push_back(in);
        sum += in;
      }
      vvi[i].push_back(sum);
    }

    vvi.push_back(vector<int>());
    REP(i, 0, n + 1) {
      int sum = 0;

      REP(j, 0, n) { sum += vvi[j][i]; }

      vvi[n].push_back(sum);
    }

    REP(i, 0, vvi.size()) {
      REP(j, 0, vvi[i].size()) { std::cout << std::setw(5) << vvi[i][j]; }
      std::cout << std::endl;
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

#define REP(i, m, n)                                                           \\
  for (int i = static_cast<int>(m); i < static_cast<int>(n); ++i)

int main() {

  int n;

  VVI vvi;
  int sum;

  while (cin >> n) {
    if (n == 0)
      break;

    REP(i, 0, n) {
      vvi.push_back(vector<int>());
      sum = 0;

      REP(j, 0, n) {
        int in;
        std::cin >> in;
        vvi[i].push_back(in);
        sum += in;
      }
      vvi[i].push_back(sum);
    }

    REP(i, 0, n + 1) {
      int sum = 0;

      REP(j, 0, n + 1) { sum += vvi[j][i]; }

      vvi[n].push_back(sum);
    }

    REP(i, 0, vvi.size()) {
      REP(j, 0, vvi[i].size()) { std::cout << std::setw(5) << vvi[i][j]; }
      std::cout << std::endl;
    }
  }
  return 0;
}
Problem p00102 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int dt[n + 1][n + 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> dt[i][j];
      }
    }
    for (int x = 0; x < n + 1; x++) {
      dt[x][n] = 0;
    }
    for (int y = 0; y < n; y++) {
      dt[n][y] = 0;
    }
    for (int k = 0; k < n; k++) {
      for (int l = 0; l < n; l++) {
        dt[k][n] += dt[k][l];
      }
    }
    for (int x = 0; x <= n; x++) {
      for (int y = 0; y < n; y++) {
        dt[n][x] += dt[y][x];
      }
    }
    for (int a = 0; a <= n; a++) {
      for (int b = 0; b <= n; b++) {
        if (dt[a][b] / 10 == 0)
          cout << "    " << dt[a][b];
        else if (dt[a][b] / 100 == 0)
          cout << "   " << dt[a][b];
        else if (dt[a][b] / 1000 == 0)
          cout << "  " << dt[a][b];
        else if (dt[a][b] / 10000 == 0)
          cout << " " << dt[a][b];
        else if (dt[a][b] / 100000 == 0)
          cout << dt[a][b];
      }
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  while (1) {
    cin >> n;
    int dt[n + 1][n + 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> dt[i][j];
      }
    }
    for (int x = 0; x < n + 1; x++) {
      dt[x][n] = 0;
    }
    for (int y = 0; y < n; y++) {
      dt[n][y] = 0;
    }
    for (int k = 0; k < n; k++) {
      for (int l = 0; l < n; l++) {
        dt[k][n] += dt[k][l];
      }
    }
    for (int x = 0; x <= n; x++) {
      for (int y = 0; y < n; y++) {
        dt[n][x] += dt[y][x];
      }
    }
    for (int a = 0; a <= n; a++) {
      for (int b = 0; b <= n; b++) {
        if (dt[a][b] / 10 == 0)
          cout << "    " << dt[a][b];
        else if (dt[a][b] / 100 == 0)
          cout << "   " << dt[a][b];
        else if (dt[a][b] / 1000 == 0)
          cout << "  " << dt[a][b];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00102 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;

  while (scanf("%d", &n), n) {
    int sum = 0, e_sum[10] = {0};
    for (int i = 0; i < n; i++) {
      int num;
      int r_sum = 0;
      for (int j = 0; j < n; j++) {
        scanf("%d", &num);
        r_sum += num;
        e_sum[j] += num;
        printf("%5d", num);
      }
      sum += r_sum;
      printf("%5d\\n", r_sum);
    }

    for (int i = 0; i < n; i++) {
      printf("%5d", e_sum[i]);
    }
    printf("%5d\\n", sum);
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;

  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++) {
      int num, sum = 0;
      for (int j = 0; j < 4; j++) {
        scanf("%d", &num);
        sum += num;
        printf("%5d", num);
      }
      printf("%5d\\n", sum);
    }
  }

  return (0);
}
Problem p00103 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int base[3] = {0, 0, 0};

void Hit() {
  if (base[2] == 1) {
    base[2] = 0;
  }
  if (base[1] == 1) {
    base[2] = 1;
  }
  if (base[0] == 1) {
    base[1] = 1;
  } else if (base[0] == 0) {
    base[0] = 1;
  }
}

void Homerun() {
  for (int i = 0; i < 3; i++) {
    base[i] = 0;
  }
}

int main() {
  int out = 0;
  int score = 0;
  int n;
  string s;
  vector<string> event;
  int eventnum = 0;

  cin >> n;
  int a = 0;
  for (int i = 0; i < 3 * n; i++) {
    while (true) {
      cin >> s;
      event.push_back(s);
      if (event.at(a) == "OUT") {
        a += 1;
        eventnum += 1;
        break;
      } else {
        a += 1;
        eventnum += 1;
      }
    }
  }

  for (int i = 0; i < eventnum; i++) {
    if (event.at(i) == "HIT") {
      if (base[2] == 1) {
        score += 1;
      }
      Hit();
    } else if (event.at(i) == "HOMERUN") {
      score += base[0] + base[1] + base[2] + 1;
      Homerun();
    } else {
      out += 1;
      if (out == 3) {
        cout << score << endl;
        for (int i = 0; i < 3; i++) {
          base[i] = 0;
        }
        score = 0;
        out = 0;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int base[3] = {0, 0, 0};

int Hit() {
  if (base[2] == 1) {
    base[2] = 0;
  }
  if (base[1] == 1) {
    base[2] = 1;
  }
  if (base[0] == 1) {
    base[1] = 1;
  } else if (base[0] == 0) {
    base[0] = 1;
  }

  return 0;
}

int Homerun() {
  for (int i = 0; i < 3; i++) {
    base[i] = 0;
  }

  return 0;
}

int main() {
  int out = 0;
  int score = 0;
  int n;
  string event[100];
  int eventnum = 0;

  cin >> n;
  int a = 0;
  for (int i = 0; i < 3 * n; i++) {
    while (true) {
      cin >> event[a];
      if (event[a] == "OUT") {
        a += 1;
        eventnum += 1;
        break;
      } else {
        a += 1;
        eventnum += 1;
      }
    }
  }

  for (int i = 0; i < eventnum; i++) {
    if (event[i] == "HIT") {
      if (base[2] == 1) {
        score += 1;
      }
      Hit();
    } else if (event[i] == "HOMERUN") {
      score += base[0] + base[1] + base[2] + 1;
      Homerun();
    } else {
      out += 1;
      if (out == 3) {
        cout << score << endl;
        for (int i = 0; i < 3; i++) {
          base[i] = 0;
        }
        score = 0;
        out = 0;
      }
    }
  }

  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int N, m = 0, rn = 0, pn = 0;
  string str;
  cin >> N;
  for (int i = 0; i < N; i++) {
    while (1) {
      cin >> str;
      if (str == "OUT") {
        m++;
        if (m == 3)
          break;
      }
      if (str == "HIT") {
        rn++;
        if (rn == 4) {
          pn++;
          rn = 3;
        }
      }
      if (str == "HOMERUN") {
        pn += rn + 1;
        rn = 0;
      }
    }
    cout << pn << endl;
    rn = 0;
    pn = 0;
    m = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int N, m = 0, rn = 0, pn = 0;
  string str;
  cin >> N;
  for (int i = 0; i < N; i++) {
    while (1) {
      cin >> str;
      if (str == "OUT") {
        m++;
        if (m == 3)
          break;
      }
      if (str == "HIT") {
        rn++;
        if (rn == 4) {
          pn++;
          rn = 3;
        }
      }
      if (str == "HOMERUN") {
        pn += rn + 1;
        rn = 0;
      }
    }
    cout << pn << endl;
    rn = 0;
    pn = 0;
  }
  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int n, ansc[100] = {}, o = 0, hr = 0, h = 0, o2 = 0;
  string event;
  cin >> n;
  int i = 0;
  int j = 0;
  while (1) {
    cin >> event;
    if (event == "OUT") {
      o++;
      o2++;
    }
    if (event == "HIT")
      h++;
    if (event == "HOMERUN")
      hr++;

    if (o2 == 3 * n)
      break;

    if (h == 4) {
      ansc[j]++;
      h--;
    } else if (o == 3) {
      o = 0;
      h = 0;
      hr = 0;
      j++;
    } else if (hr == 1) {
      ansc[j] += h + 1;
      h = 0;
      hr = 0;
    }
    i++;
  }
  for (int j = 0; j < n; j++)
    cout << ansc[j] << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int n, ansc = 0, count = 0, count1 = 0, count2 = 0, count3 = 0;
  string event[100];
  cin >> n;
  int i = 0;
  while (1) {
    cin >> event[i];
    if (event[i] == "OUT") {
      count++;
      count3++;
    }
    if (event[i] == "HIT")
      count1++;
    if (event[i] == "HOMERUN")
      count2++;
    if (count3 == 3 * n)
      break;

    if (count == 3) {
      count = 0;
      count1 = 0;
      count2 = 0;
    } else if (count2 == 1) {
      ansc += count1 + 1;
      count1 = 0;
      count2 = 0;
    } else if (count1 == 4) {
      ansc++;
      count1--;
    }
    i++;
  }
  cout << ansc << endl;
  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>

using namespace std;

int main() {
  string batter;
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int runner = 0, num = 0, out = 0;
    while (1) {
      cin >> batter;

      if (batter == "HIT") {
        runner++;
        if (runner == 4) {
          runner--;
          num++;
        }
      } else if (batter == "HOMERUN") {
        num++;
        num += runner;
        runner = 0;
      } else if (batter == "OUT") {
        out++;
        if (out == 3) {
          runner = 0;
          break;
        }
      }
    }
    cout << num << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, i = 1;
  int base = 0, sum[3] = {}, out_count = 0;
  string str;

  cin >> n;

  while (1) {

    if (i > n)
      break;
    cin >> str;

    if (out_count >= 3) {
      base = 0;
      i++;
    }
    if (base >= 4) {
      sum[i]++;
      base = base - 1;
    }
    if (str == "HIT") {
      base++;
    } else if (str == "OUT") {
      out_count++;
    } else if (str == "HOMERUN") {
      sum[i] += base + 1;
      base = 0;
    }
  }
  cout << sum[1] << endl;
  cout << sum[2] << endl;

  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <array>
#include <iostream>

class Baseball {
private:
  int out_count;
  std::array<int, 4> runner; // first second third home
                             // runner:1 no:0 home:point

public:
  Baseball() {
    out_count = 0;
    for (int i = 0; i < 4; ++i)
      runner[i] = 0;
  }

  void ining() {
    while (out_count != 3) {
      std::string str;
      std::cin >> str;

      if (str == "HIT")
        hit();
      else if (str == "OUT")
        out();
      else if (str == "HOMERUN")
        homerun();
    }

    std::cout << runner[3] << std::endl;
    return;
  }

  void hit() {
    for (int i = 0; i < 4; ++i) {
      if (runner[i] == 0) {
        runner[i] = 1;
        return;
      }
      if (i == 3)
        ++runner[i];
    }
  }

  void out() { ++out_count; }

  void homerun() {
    for (int i = 0; i < 3; ++i) {
      if (runner[i] == 1) {
        ++runner[3];
        runner[i] = 0;
      }
    }
    ++runner[3];
  }
};

int main() {
  int n;
  std::cin >> n;

  for (int k = 0; k < n; ++k) {
    Baseball game;
    game.ining();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <array>
#include <iostream>

class Baseball {
private:
  int out_count;
  std::array<int, 4> runner;

public:
  Baseball() {
    out_count = 0;
    for (int i = 0; i < 4; ++i)
      runner[i] = 0;
  }

  void ining() {
    while (out_count != 3) {
      std::string str;
      std::getline(std::cin, str);

      if (str == "HIT")
        hit();
      else if (str == "OUT")
        out();
      else
        homerun();
    }

    return;
  }

  void hit() {
    int i;
    for (i = 0; i < 4; ++i) {
      if (runner[i] == 0) {
        runner[i] = 1;
        return;
      }
    }
    ++runner[i];
  }

  void out() { ++out_count; }

  void homerun() {
    for (int i = 0; i < 4; ++i) {
      if (runner[i] == 1) {
        ++runner[3];
        runner[i] = 0;
      }
    }
    ++runner[3];
  }

  void show() { std::cout << runner[3] << std::endl; }
};

int main() {
  int n;
  std::cin >> n;
  Baseball game[n];

  for (int k = 0; k < n; ++k) {
    game[k].ining();
  }

  for (int k = 0; k < n; ++k) {
    game[k].show();
  }

  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Time Limit Exceeded

// 0103
#include <stdio.h>
#include <string.h>
int main() {
  int n, op, f, se, t, r = 0;
  char in[16];
  scanf("%d", &n);
  while (n--) {
    r = 0;
    op = 0;
    f = 0;
    se = 0;
    t = 0;
    while (op < 3) {
      scanf("%s", in);
      if (in[1] == 'I') {
        r += t;
        t = se;
        se = f;
        f = 1;
      } else if (in[1] == 'U') {
        op++;
      } else {
        r += f + se + t + 1;
        f = 0;
        se = 0;
        t = 0;
      }
    }
    printf("%d\\n", r);
  }
  return 0;
}

Error: TLE

Fixed submission:

// 0103
#include <stdio.h>
#include <string.h>
int main() {
  int n, op, rn[3] = {0}, r;
  char s[8];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    r = 0;
    op = 0;
    while (1) {
      if (strcmp("OUT", s) == 0) {
        op++;
      } else if (strcmp("HIT", s)) {
        if (rn[2]) {
          rn[2] = 0;
          r++;
        }
        if (rn[1]) {
          rn[1] = 0;
          rn[2] = 1;
        }
        if (rn[0]) {
          rn[1] = 1;
        }
        rn[0] = 1;
      } else {
        for (int j = 0; j < 3; j++) {
          if (rn[j] == 1) {
            rn[j] = 0;
            r++;
          }
          r++;
        }
      }
      if (op >= 3) {
        break;
      }
    }
    printf("%d\\n", r);
  }
  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int base[6], out = 0, score = 0, n, eventnum = 0, a = 0;
vector<string> event;
string s;

void Hit() {
  base[2] = 0;
  if (base[1])
    base[2] = 1;
  if (base[0])
    base[1] = 1;
  base[0] = 1;
}

void Homerun() {
  for (int j = 0; j < 3; j++) {
    base[j] = 0;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    while (true) {
      cin >> s;
      event.push_back(s);
      a++;
      eventnum++;
      if (event.at(a - 1) == "OUT")
        break;
    }
  }
  for (int i = 0; i < eventnum; i++) {
    if (event.at(i) == "HIT") {
      if (base[2] == 1)
        score += 1;
      Hit();
    } else if (event.at(i) == "HOMERUN") {
      score += (base[0] + base[1] + base[2] + 1);
      Homerun();
    } else {
      out++;
      if (out == 3) {
        cout << score << endl;
        for (int j = 0; j < 3; j++)
          base[j] = 0;
        score = out = 0;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int base[6], out = 0, score = 0, n, eventnum = 0, a = 0;
string event[106];

void Hit() {
  base[2] = 0;
  if (base[1])
    base[2] = 1;
  if (base[0])
    base[1] = 1;
  base[0] = 1;
}

void Homerun() {
  for (int j = 0; j < 3; j++) {
    base[j] = 0;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    while (true) {
      cin >> event[a];
      a++;
      eventnum++;
      if (event[a - 1] == "OUT")
        break;
    }
  }
  for (int i = 0; i < eventnum; i++) {
    if (event[i] == "HIT") {
      if (base[2] == 1)
        score += 1;
      Hit();
    } else if (event[i] == "HOMERUN") {
      score += (base[0] + base[1] + base[2] + 1);
      Homerun();
    } else {
      out++;
      if (out == 3) {
        cout << score << endl;
        for (int j = 0; j < 3; j++)
          base[j] = 0;
        score = out = 0;
      }
    }
  }
  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  int o, i, out = 0, b = 0, p[100];
  string ev;

  cin >> o;

  for (i = 0; i < o; i++) {

    p[i] = 0;

    while (1) {

      cin >> ev;

      if (ev == "HIT") {
        b++;

        if (b == 4) {
          b--;

          p[i]++;
        }
      }

      else if (ev == "HOMERUN") {
        p[i] += b + 1;

        b = 0;
      }

      else if (ev == "OUT") {
        out++;
      }

      if (out == 3)
        break;
    }

    out = 0;
    b = 0;
  }

  for (i = 0; i < o; i++) {
    cout << p[i] << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int o, i, out = 0, b = 0, p[10];
  string ev;

  cin >> o;

  for (i = 0; i < o; i++) {

    p[i] = 0;

    while (1) {

      cin >> ev;

      if (ev == "HIT") {
        b++;

        if (b == 4) {
          b--;

          p[i]++;
        }
      }

      else if (ev == "HOMERUN") {
        p[i] += b + 1;

        b = 0;
      }

      else if (ev == "OUT") {
        out++;
      }

      if (out == 3)
        break;
    }

    out = 0;
    b = 0;
  }

  for (i = 0; i < o; i++) {
    cout << p[i] << endl;
  }

  return 0;
}
Problem p00103 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(void) {
  // Here your code !
  int n;
  cin >> n;
  string a;
  bool run[3] = {false, false, false};
  int out = 0, e = 0;
  int point[50] = {};
  int j = 0;
  int k = 0;
  while (cin >> a) {
    if (a == "HIT") {
      if (run[2]) {
        point[e]++;
        run[2] = false;
      }
      if (run[1]) {
        run[2] = true;
        run[1] = false;
      }
      if (run[0]) {
        run[1] = true;
        run[0] = false;
      }
      run[0] = true;
    } else if (a == "OUT") {
      out++;
      if (out == 3) {
        out = 0;
        run[0] = false;
        run[1] = false;
        run[2] = false;
        e++;
      }
    } else {
      k = 0;
      if (run[0])
        k++;
      if (run[1])
        k++;
      if (run[2])
        k++;
      run[0] = false;
      run[1] = false;
      run[2] = false;
      REP(i, k) { point[e]++; }
      point[e]++;
    }
    j++;
  }
  REP(i, n) { cout << point[i] << endl; }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(void) {
  // Here your code !
  int n;
  cin >> n;
  vector<string> a(101);
  bool run[3] = {false, false, false};
  int out = 0, e = 0;
  int point[50] = {};
  int j = 0;
  int k = 0;
  while (cin >> a[j]) {
    if (a[j] == "HIT") {
      if (run[2]) {
        point[e]++;
        run[2] = false;
      }
      if (run[1]) {
        run[2] = true;
        run[1] = false;
      }
      if (run[0]) {
        run[1] = true;
        run[0] = false;
      }
      run[0] = true;
    } else if (a[j] == "OUT") {
      out++;
      if (out == 3) {
        out = 0;
        run[0] = false;
        run[1] = false;
        run[2] = false;
        e++;
      }
    } else {
      k = 0;
      if (run[0])
        k++;
      if (run[1])
        k++;
      if (run[2])
        k++;
      run[0] = false;
      run[1] = false;
      run[2] = false;
      REP(i, k) { point[e]++; }
      point[e]++;
    }
    j++;
  }
  REP(i, n) { cout << point[i] << endl; }
}
Problem p00103 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 114514810
#define ELEM(array) (sizeof(array) / sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT = 0, count_OUT = 0;
int Point = 0;
string S;

void solve() {
  while (count_OUT < 3) {
    cin >> S;
    if (S == "HIT") {
      count_HIT++;
      if (count_HIT == 4) {
        Point++;

        count_HIT--;
      }
    } else if (S == "HOMERUN") {
      Point += count_HIT + 1;

      count_HIT = 0;
    } else
      count_OUT++;
  }
  cout << Point << endl;
  count_OUT = 0;
  count_HIT = 0;
  Point = 0;

  return;
}

int main() {
  cin >> n;
  REP(j, n) { solve(); }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 114514810
#define ELEM(array) (sizeof(array) / sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT = 0, count_OUT = 0;
int Point[2] = {0, 0};
int i = 0;
string S;

void solve() {
  while (count_OUT == 3) {
    cin >> S;
    if (S == "HIT") {
      count_HIT++;
      if (count_HIT == 4) {
        Point[i]++;
        count_HIT = 0;
      }
    } else if (S == "HOMERUN") {
      Point[i] = count_HIT + 1;
      count_HIT = 0;
    } else
      count_OUT++;
  }
  count_OUT = 0;
  count_HIT = 0;
  i ^= 1;
  n++;
  return;
}

int main() {
  cin >> n;
  REP(i, n) { solve(); }

  cout << Point[0] << endl << Point[1] << endl;

  return 0;
}