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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define mp(a, b) make_pair((a), (b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;

// →↑←↓
const int dx[] = {
    -1, -1, -1, 0, 0,  1,  1,  1, -1, -1, -1, 0, 0,
    0,  1,  1,  1, -1, -1, -1, 0, 0,  0,  1,  1, 1,
};
const int dy[] = {
    -1, 0,  1, -1, 1,  -1, 0, 1,  -1, 0, 1,  -1, 0,
    1,  -1, 0, 1,  -1, 0,  1, -1, 0,  1, -1, 0,  1,
};
const int dz[] = {
    0, 0, 0, 0, 0,  0,  0,  0,  1,  1,  1,  1,  1,
    1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};

const double EPS = 1e-9;

int main() {
  while (true) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0)
      break;
    vector<vector<vector<char>>> F(
        n, vector<vector<char>>(n, vector<char>(n, '.')));
    bool win = false;
    bool black = true;
    int turn;
    bool end = false;
    for (int t = 0; t < p; t++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      if (end)
        continue;
      for (int h = 0; h < n; h++) {
        if (F[x][y][h] == '.') {
          if (t % 2 == 0) {
            F[x][y][h] = 'b';
          } else {
            F[x][y][h] = 'w';
          }
          break;
        }
      }

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          for (int k = 0; k < n; k++) {
            for (int l = 0; l < 26; l++) {
              if (F[i][j][k] == '.')
                continue;
              int ddx = dx[l];
              int ddy = dy[l];
              int ddz = dz[l];
              int nx = i;
              int ny = j;
              int nz = k;
              bool ok = true;
              for (int o = 0; o < m; o++) {
                if (not(0 <= nx and nx < n and 0 <= ny and ny < n and
                        0 <= nz and nz < n and F[nx][ny][nz] == F[i][j][k])) {
                  ok = false;
                }
                nx += ddx;
                ny += ddy;
                nz += ddz;
              }
              if (ok) {
                turn = t + 1;
                win = true;
                black = turn % 2;
                end = true;
              }
            }
          }
        }
      }
    }
    if (win) {
      if (black) {
        cout << "Black";
      } else {
        cout << "White";
      }
      cout << " " << turn << endl;
    } else {
      cout << "Draw" << endl;
    }
  }
  return 0;
}

Error: 0
0 0 0
0 0 0
0 0 1
0 0 0
0 0 1
0 0 2
1 1 0
0 2 0
0 0 0
1 2 0
1 0 0
2 2 0
0 0 0
1 1 0
0 0 0
0 0 1
2 2 0
2 2 0
2 2 1
0 0 0
0 0 1
0 0 2
2 2 0
2 2 1
2 2 2
2 2 0
2 2 1
2 2 2
2 2 3
3 3 0
0 0 0
0 0 1
0 0 2
0 0 3
3 3 0
3 3 1
3 3 0
3 3 1
3 3 2
3 3 0
3 3 1
3 3 2
3 3 3
3 0 0
1 1 0
1 1 1


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define mp(a, b) make_pair((a), (b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;

// →↑←↓
const int dx[] = {
    -1, -1, -1, 0, 0,  1,  1,  1, -1, -1, -1, 0, 0,
    0,  1,  1,  1, -1, -1, -1, 0, 0,  0,  1,  1, 1,
};
const int dy[] = {
    -1, 0,  1, -1, 1,  -1, 0, 1,  -1, 0, 1,  -1, 0,
    1,  -1, 0, 1,  -1, 0,  1, -1, 0,  1, -1, 0,  1,
};
const int dz[] = {
    0, 0, 0, 0, 0,  0,  0,  0,  1,  1,  1,  1,  1,
    1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};

const double EPS = 1e-9;

int main() {
  while (true) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0)
      break;
    vector<vector<vector<char>>> F(
        n, vector<vector<char>>(n, vector<char>(n, '.')));
    bool win = false;
    bool black = true;
    int turn;
    bool end = false;
    for (int t = 0; t < p; t++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      if (end)
        continue;
      for (int h = 0; h < n; h++) {
        cerr << x << " " << y << " " << h << endl;
        if (F[x][y][h] == '.') {
          if (t % 2 == 0) {
            F[x][y][h] = 'b';
          } else {
            F[x][y][h] = 'w';
          }
          break;
        }
      }

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          for (int k = 0; k < n; k++) {
            for (int l = 0; l < 26; l++) {
              if (F[i][j][k] == '.')
                continue;
              int ddx = dx[l];
              int ddy = dy[l];
              int ddz = dz[l];
              int nx = i;
              int ny = j;
              int nz = k;
              bool ok = true;
              for (int o = 0; o < m; o++) {
                if (not(0 <= nx and nx < n and 0 <= ny and ny < n and
                        0 <= nz and nz < n and F[nx][ny][nz] == F[i][j][k])) {
                  ok = false;
                }
                nx += ddx;
                ny += ddy;
                nz += ddz;
              }
              if (ok) {
                turn = t + 1;
                win = true;
                black = turn % 2;
                end = true;
              }
            }
          }
        }
      }
    }
    if (win) {
      if (black) {
        cout << "Black";
      } else {
        cout << "White";
      }
      cout << " " << turn << endl;
    } else {
      cout << "Draw" << endl;
    }
  }
  return 0;
}