Problem p00036 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define SZ(n) (int)n.size()
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back
char ta[10][10];
int main() {
  while (cin >> ta[1][1]) {
    for (int i = 1; i <= 8; i++)
      for (int j = (i == 1) + 1; j <= 8; j++)
        cin >> ta[i][j];

    for (int i = 1; i <= 8; i++) {
      for (int j = 1; j <= 8; j++) {
        char ans = '?';
        if (ta[i][j] == '1') {
          if (ta[i + 1][j] == '1' && ta[i][j + 1] == '1' &&
              ta[i + 1][j + 1] == '1')
            ans = 'A';

          else if (ta[i + 1][j] == '1' && ta[i + 1][j] == '1' &&
                   ta[i + 3][j] == '1')
            ans = 'B';

          else if (ta[i][j + 1] == '1' && ta[i][j + 2] == '1' &&
                   ta[i][j + 3] == '1')
            ans = 'C';

          else if (ta[i + 1][j] == '1' && ta[i + 1][j - 1] == '1' &&
                   ta[i + 2][j - 1] == '1')
            ans = 'D';

          else if (ta[i][j + 1] == '1' && ta[i + 1][j + 1] == '1' &&
                   ta[i + 1][j + 2] == '1')
            ans = 'E';

          else if (ta[i + 1][j] == '1' && ta[i + 1][j + 1] == '1' &&
                   ta[i + 2][j + 1] == '1')
            ans = 'F';

          else if (ta[i][j + 1] == '1' && ta[i + 1][j] == '1' &&
                   ta[i + 1][j - 1] == '1')
            ans = 'G';
        }
        if (ans != '?') {
          cout << ans << endl;
          goto next;
        }
      }
    }

  next:;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int stoi(string x) {
  stringstream ss;
  ss << x;
  int tmp;
  ss >> tmp;
  return tmp;
}
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
char ta[12][12];
int main() {
  while (true) {
    int y, x;
    for (int i = 0; i < 12; i++)
      for (int j = 0; j < 12; j++)
        ta[i][j] = '0';
    bool f = 1;
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        char now;
        cin >> now;
        if (now == EOF) {
          return 0;
        }
        if (now == '1' && f) {
          y = i, x = j;
          f = 0;
        }
        ta[i][j] = now;
      }
    }
    if (ta[y][x + 1] == '1' && ta[y + 1][x] == '1' && ta[y + 1][x + 1] == '1')
      cout << "A";

    else if (ta[y + 1][x] == '1' && ta[y + 2][x] == '1' && ta[y + 3][x] == '1')
      cout << "B";

    else if (ta[y][x + 1] == '1' && ta[y][x + 2] == '1' && ta[y][x + 3] == '1')
      cout << "C";

    else if (ta[y][x + 1] == '1' && ta[y + 1][x + 1] == '1' &&
             ta[y + 1][x + 2] == '1')
      cout << "E";

    else if (ta[y + 1][x] == '1' && ta[y + 1][x + 1] == '1' &&
             ta[y + 2][x + 1] == '1')
      cout << "F";

    else if (ta[y + 2][x - 1] == '1' && ta[y + 1][x] == '1' &&
             ta[y + 1][x - 1] == '1')
      cout << "D";
    else
      cout << "G";
    cout << endl;
  }

  return 0;
}