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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, b, n) for (int i = b; i < n; ++i)
#define REPR(i, b, n) for (int i = n - 1; i >= b; --i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n >> b) & 1)
#define PI acos(-1.0)

#define LIM 1000010

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int dist_fl[] = {9, 24, 3, 15, 10, 17, 8};
vector<string> surf(8);

char solve() {

  int cnt = 0, dist = 0;

  for (int i = 0; i < 8; ++i) {
    for (int j = 0; j < 8; ++j) {

      if (cnt != 0)
        dist++;

      if (surf[i][j] == '1')
        cnt++;

      if (cnt == 4) {
        for (int k = 0; k < 7; ++k) {
          if (dist_fl[k] == dist)
            return (char)('A' + k);
        }
      }
    }
  }
}

int main() {

  while (cin >> surf[0] >> surf[1] >> surf[2] >> surf[3] >> surf[4] >>
             surf[5] >> surf[6] >> surf[7],
         !cin.eof()) {

    cin.ignore();
    cout << solve() << endl;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int field[8][8] = {0};
  int i, j;
  int judge[7];

  for (j = 0; j < 8; j++) {
    for (i = 0; i < 8; i++) {
      scanf("%d", &field[i][j]);
    }
  }

  for (j = 0; j < 8; j++) {
    for (i = 0; i < 8; j++) {

      if (field[i][j] == 1) {
        judge[0] += 1;
        judge[1] += 1;
        judge[2] += 1;
        judge[3] += 0;
        judge[4] += 1;
        judge[5] += 1;
        judge[6] += 0;
      }
      if (field[i][j + 1] == 1) {
        judge[0] += 1;
        judge[1] += 1;
        judge[2] += 0;
        judge[3] += 1;
        judge[4] += 0;
        judge[5] += 1;
        judge[6] += 1;
      }
      if (field[i + 1][j] == 1) {
        judge[0] += 1;
        judge[1] += 0;
        judge[2] += 1;
        judge[3] += 1;
        judge[4] += 1;
        judge[5] += 0;
        judge[6] += 1;
      }
      if (field[i + 1][j + 1] == 1) {
        judge[0] += 1;
        judge[1] += 0;
        judge[2] += 0;
        judge[3] += 1;
        judge[4] += 1;
        judge[5] += 1;
        judge[6] += 1;
      }
      if (field[i][j + 2] == 1) {
        judge[0] += 0;
        judge[1] += 1;
        judge[2] += 0;
        judge[3] += 1;
        judge[4] += 0;
        judge[5] += 0;
        judge[6] += 0;
      }
      if (field[i + 2][j] == 1) {
        judge[0] += 0;
        judge[1] += 0;
        judge[2] += 1;
        judge[3] += 0;
        judge[4] += 0;
        judge[5] += 0;
        judge[6] += 1;
      }
      if (field[i + 1][j + 2] == 1) {
        judge[0] += 0;
        judge[1] += 0;
        judge[2] += 0;
        judge[3] += 0;
        judge[4] += 0;
        judge[5] += 1;
        judge[6] += 0;
      }
      if (field[i + 2][j + 1] == 1) {
        judge[0] += 0;
        judge[1] += 0;
        judge[2] += 0;
        judge[3] += 0;
        judge[4] += 1;
        judge[5] += 0;
        judge[6] += 0;
      }
      if (field[i + 3][j] == 1) {
        judge[0] += 0;
        judge[1] += 0;
        judge[2] += 1;
        judge[3] += 0;
        judge[4] += 0;
        judge[5] += 0;
        judge[6] += 0;
      }
      if (field[i][j + 3] == 1) {
        judge[0] += 0;
        judge[1] += 1;
        judge[2] += 0;
        judge[3] += 0;
        judge[4] += 0;
        judge[5] += 0;
        judge[6] += 0;
      }

      if (judge[0] == 4) {
        printf("A");
        return 0;
      }
      if (judge[1] == 4) {
        printf("B");
        return 0;
      }
      if (judge[2] == 4) {
        printf("C");
        return 0;
      }
      if (judge[3] == 4) {
        printf("D");
        return 0;
      }
      if (judge[4] == 4) {
        printf("E");
        return 0;
      }
      if (judge[5] == 4) {
        printf("F");
        return 0;
      }
      if (judge[6] == 4) {
        printf("G");
        return 0;
      }

      judge[0] = 0;
      judge[1] = 0;
      judge[2] = 0;
      judge[3] = 0;
      judge[4] = 0;
      judge[5] = 0;
      judge[6] = 0;
    }
  }
}