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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

  int n;
  char field[1001][1001];
  // int under[1001][1001];
  // int right[1001][1001];
  // int squareSize[1001][1001];

  vector<vector<int>> under;
  vector<vector<int>> right;
  vector<vector<int>> squareSize;

  vector<int> v(1001, -1);
  vector<int> vvv(1001, 0);

  for (int i = 0; i < 1001; i++) {
    under.push_back(v);
    right.push_back(v);
    squareSize.push_back(vvv);
  }

  while (cin >> n && n != 0) {
    int maxSize = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> field[i][j];
      }
    }

    for (int i = 0; i < 1001; i++) {
      for (int j = 0; j < 1001; j++) {
        under[i][j] = -1;
        right[i][j] = -1;
        squareSize[i][j] = 0;
      }
      // fill(under[i],under[i]+1001,-1);
      // fill(right[i],right[i]+1001,-1);
      // fill(squareSize[i],squareSize[i]+1001,0);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        // º
        if (field[i][j] == '*') {

        } else if (i - 1 < 0 || field[i - 1][j] == '*') {
          int cnt = 0;
          for (int k = i + 1; k < n; k++) {
            if (field[k][j] == '*')
              break;
            cnt++;
          }
          under[i][j] = cnt;
        } else if (i - 1 >= 0 && field[i][j] == '.') {
          under[i][j] = under[i - 1][j] - 1;
        }
        // E
        if (field[i][j] == '*') {

        } else if (j - 1 < 0 || field[i][j - 1] == '*') {
          int cnt = 0;
          for (int k = j + 1; k < n; k++) {
            if (field[i][k] == '*')
              break;
            cnt++;
          }
          right[i][j] = cnt;
        } else if (j - 1 >= 0 && field[i][j] == '.') {
          right[i][j] = right[i][j - 1] - 1;
        }
      }
    }
    // ì¬Å«ésquareÌTCYðmè
    for (int i = n - 1; i >= 0; i--) {
      for (int j = n - 1; j >= 0; j--) {
        if (field[i][j] == '.') {
          if (i + 1 < n && j + 1 < n && field[i + 1][j + 1] == '.') {
            // TuXNFAÌTCY
            int ss = squareSize[i + 1][j + 1];
            // TuXNFAÉdËé`ÅXNFAªìêéê
            if (under[i][j] >= ss && right[i][j] >= ss) {
              squareSize[i][j] = ss + 1;
              maxSize = max(maxSize, squareSize[i][j]);
            }
            // ìêÈ¢êAunderÆrightÌTCY©çAìêéTCYðmè
            else {
              int m = min(under[i][j], right[i][j]);
              squareSize[i][j] = m + 1;
              maxSize = max(maxSize, squareSize[i][j]);
            }
          }
          // EºªAX^Ü½ÍtB[hOÌê
          else {
            squareSize[i][j] = 1;
            maxSize = max(maxSize, squareSize[i][j]);
          }
        }
        // ©gÌêªAX^Ìê
        else {
          squareSize[i][j] = 0;
        }
      }
    }
    cout << maxSize << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

  int n;
  char field[1001][1001];
  int under[1001][1001];
  int right[1001][1001];
  int squareSize[1001][1001];

  while (cin >> n && n != 0) {
    int maxSize = 0;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> field[i][j];
      }
    }

    for (int i = 0; i < 1001; i++) {
      for (int j = 0; j < 1001; j++) {
        under[i][j] = -1;
        right[i][j] = -1;
        squareSize[i][j] = 0;
      }
      // fill(under[i],under[i]+1001,-1);
      // fill(right[i],right[i]+1001,-1);
      // fill(squareSize[i],squareSize[i]+1001,0);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        // º
        if (field[i][j] == '*') {

        } else if (i - 1 < 0 || field[i - 1][j] == '*') {
          int cnt = 0;
          for (int k = i + 1; k < n; k++) {
            if (field[k][j] == '*')
              break;
            cnt++;
          }
          under[i][j] = cnt;
        } else if (i - 1 >= 0 && field[i][j] == '.') {
          under[i][j] = under[i - 1][j] - 1;
        }
        // E
        if (field[i][j] == '*') {

        } else if (j - 1 < 0 || field[i][j - 1] == '*') {
          int cnt = 0;
          for (int k = j + 1; k < n; k++) {
            if (field[i][k] == '*')
              break;
            cnt++;
          }
          right[i][j] = cnt;
        } else if (j - 1 >= 0 && field[i][j] == '.') {
          right[i][j] = right[i][j - 1] - 1;
        }
      }
    }
    // ì¬Å«ésquareÌTCYðmè
    for (int i = n - 1; i >= 0; i--) {
      for (int j = n - 1; j >= 0; j--) {
        if (field[i][j] == '.') {
          if (i + 1 < n && j + 1 < n && field[i + 1][j + 1] == '.') {
            // TuXNFAÌTCY
            int ss = squareSize[i + 1][j + 1];
            // TuXNFAÉdËé`ÅXNFAªìêéê
            if (under[i][j] >= ss && right[i][j] >= ss) {
              squareSize[i][j] = ss + 1;
              maxSize = max(maxSize, squareSize[i][j]);
            }
            // ìêÈ¢êAunderÆrightÌTCY©çAìêéTCYðmè
            else {
              int m = min(under[i][j], right[i][j]);
              squareSize[i][j] = m + 1;
              maxSize = max(maxSize, squareSize[i][j]);
            }
          }
          // EºªAX^Ü½ÍtB[hOÌê
          else {
            squareSize[i][j] = 1;
            maxSize = max(maxSize, squareSize[i][j]);
          }
        }
        // ©gÌêªAX^Ìê
        else {
          squareSize[i][j] = 0;
        }
      }
    }
    cout << maxSize << endl;
  }

  return 0;
}