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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[1001][1001];
int latte(int i, int j, int k) {
  return dp[i + k][j + k] - dp[i + k][j - 1] - dp[i - 1][j + k] +
         dp[i - 1][j - 1];
}
int main() {
  int n;
  while (cin >> n, n) {
    fill(dp[0], dp[0] + 1001 * 1001, 0);
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      for (int j = 0; j < n; j++) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
        if (str[j] == '*')
          dp[i + 1][j + 1]++;
      }
    }
    int Max = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (latte(i, j, 0))
          continue;
        int lb = 0, ub = min(n - i, n - j) + 1;
        while (ub - lb > 1) {
          int k = (ub + lb) / 2;
          // if(i+k>n||j+k>n)ub=k;
          if (latte(i, j, k))
            ub = k;
          else
            lb = k;
        }
        Max = max(Max, lb + 1);
      }
    }
    cout << Max << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[1001][1001];
int latte(int i, int j, int k) {
  return dp[i + k][j + k] - dp[i + k][j - 1] - dp[i - 1][j + k] +
         dp[i - 1][j - 1];
}
int main() {
  int n;
  while (cin >> n, n) {
    fill(dp[0], dp[0] + 1001 * 1001, 0);
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      for (int j = 0; j < n; j++) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
        if (str[j] == '*')
          dp[i + 1][j + 1]++;
      }
    }
    int Max = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (latte(i, j, 0))
          continue;
        int lb = 0, ub = max(n - i, n - j) + 1;
        while (ub - lb > 1) {
          int k = (ub + lb) / 2;
          // if(i+k>n||j+k>n)ub=k;
          if (latte(i, j, k))
            ub = k;
          else
            lb = k;
        }
        Max = max(Max, lb + 1);
      }
    }
    cout << Max << endl;
  }
}
Problem p00092 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <stack>
using namespace std;

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repl(i, n, s) for (int i = s; i <= n; ++i)

#define N 1002

typedef pair<int, int> P;

int main() {
  int n, dp[N][N], ans;
  char c;
  stack<P> st;
  while (1) {
    cin >> n;
    if (!n)
      break;
    ans = 0;
    rep(i, n) {
      rep(j, n) {
        cin >> c;
        if (c == '*') {
          dp[i][j] = 0;
        } else {
          dp[i][j] = i ? dp[i - 1][j] + 1 : 1;
        }
        int back = j;
        while (!st.empty() && dp[i][j] < st.top().second) {
          if (st.top().first + st.top().second <= j) {
            ans = max(ans, st.top().second);
          }
          back = st.top().first;
          st.pop();
        }
        if (st.empty() || st.top().second < dp[i][j]) {
          st.push(P(back, dp[i][j]));
        }
      }
      while (!st.empty()) {
        if (st.top().first + st.top().second <= n) {
          ans = max(ans, st.top().second);
        }
        st.pop();
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

#define N 1000

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) > (b) ? (b) : (a))

int main() {
  char map[N][N];
  int l[N][N], ans, n, dp[N][N], c;
  while (1) {
    cin >> n;
    if (!n)
      break;
    c = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> map[i][j];
        l[i][j] = 0;
        if (map[i][j] == '*') {
          c++;
          if (i) {
            int k = 1;
            while (map[i - k][j] != '*') {
              l[i - k][j] = k;
              if (i < (++k))
                break;
            }
          }
        }
      }
    }
    for (int j = 0; j < n; ++j) {
      int k = 1;
      while (map[n - k][j] != '*') {
        l[n - k][j] = k;
        if (n < (++k))
          break;
      }
    }
    if (c == n * n) {
      cout << "0" << endl;
      continue;
    }
    ans = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
        dp[j][j] = l[i][j];
      int r = 0;
      for (int l = 0; l < n; ++l) {
        if (r < l)
          r = l;
        while (dp[l][r] > (r - l + 1) && r < n - 1) {
          r++;
          for (int m = l; m < r; ++m) {
            dp[m][r] = min(dp[m][r - 1], dp[r][r]);
          }
        }
        ans = max(ans, min(dp[l][r], r - l + 1));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00092 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int n;
  char m[1000][1001];
  while (cin >> n && n) {
    int a = 0;
    for (int i = 0; i < n; ++i)
      cin >> m[i];
    for (int i = 0; i <= n - a; ++i) {
      for (int j = 0; j <= n - a; ++j) {
        if (m[i][j] == '.') {
          bool f = true;
          for (int k = 1; f && i + k <= n && j + k <= n; ++k) {
            for (int l = 0; l <= k; ++l) {
              if (m[i + l][j + k] != '.') {
                a = max(a, k);
                j += k;
                f = false;
                break;
              }
              if (m[i + k][j + l] != '.') {
                a = max(a, k);
                j += l;
                f = false;
                break;
              }
            }
          }
        }
      }
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  char m[1000][1001];
  while (cin >> n && n) {
    int a = 0;
    for (int i = 0; i < n; ++i)
      cin >> m[i];
    for (int i = 0; i < n; ++i) {
      if (a + i > n)
        break;
      for (int j = 0; j < n; ++j) {
        if (a + j > n)
          break;
        if (m[i][j] == '.') {
          bool f = true;
          for (int k = 1; f; ++k) {
            if (i + k == n || j + k == n) {
              a = max(a, k);
              break;
            }
            for (int l = 0; l <= k; ++l) {
              if (m[i + k][j + l] != '.' || m[i + l][j + k] != '.') {
                a = max(a, k);
                f = false;
                break;
              }
            }
          }
        }
      }
    }
    cout << a << endl;
  }
  return 0;
}
Problem p00092 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<vector<char>> d(n, vector<char>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> d[i][j];
      }
    }
    vector<vector<int>> dd(n, vector<int>(n));
    int c = 0;
    for (int i = 0; i < n; i++) {
      int cc = 0;
      for (int j = n - 1; j >= 0; j--) {
        if (d[i][j] == '.') {
          cc++;
        } else {
          cc = 0;
        }
        dd[i][j] = cc;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dd[i][j] > c) {
          int ccc = dd[i][j];
          for (int k = 0; i + k < n; k++) {
            if (dd[i + k][j] <= c) {
              break;
            }
            ccc = min(ccc, dd[i + k][j]);
            if (ccc <= k + 1) {
              c = max(c, ccc);
            }
          }
        }
      }
    }
    cout << c << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<vector<char>> d(n, vector<char>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> d[i][j];
      }
    }
    vector<vector<int>> dd(n, vector<int>(n));
    int c = 0;
    for (int i = 0; i < n; i++) {
      int cc = 0;
      for (int j = n - 1; j >= 0; j--) {
        if (d[i][j] == '.') {
          cc++;
        } else {
          cc = 0;
        }
        dd[i][j] = cc;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dd[i][j] > c) {
          int ccc = dd[i][j];
          for (int k = 0; i + k < n; k++) {
            if (dd[i + k][j] == 0) {
              break;
            }
            ccc = min(ccc, dd[i + k][j]);
            if (ccc <= k + 1) {
              c = max(c, ccc);
            }
          }
        }
      }
    }
    cout << c << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    char c[1000][1000];
    int dp[1000][1000] = {0};
    int m = 0;
    for (int i = 0; i < n; i++) {
      cin >> c[i];
      for (int j = 0; j < n; j++) {
        if (!i || !j) {
          if (c[i][j] == '.') {
            dp[i][j] = 1;
          } else
            dp[i][j] = 0;
        }
      }
    }
    for (int i = 1; i < n; i++) {
      for (int j = 1; j < n; j++) {
        if (c[i][j] == '.') {
          dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
          m = max(m, dp[i][j]);
        }
      }
    }
    cout << m << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

char c[1000][1000];
int dp[1000][1000];
int main() {
  int n;
  while (cin >> n, n) {
    int m = 0;
    for (int i = 0; i < n; i++) {
      cin >> c[i];
      for (int j = 0; j < n; j++) {

        if (c[i][j] == '.') {
          dp[i][j] = 1;
          m = 1;
        } else
          dp[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (i > 0)
          dp[i][j] += dp[i - 1][j];
        if (j > 0)
          dp[i][j] += dp[i][j - 1];
        if (i > 0 && j > 0)
          dp[i][j] -= dp[i - 1][j - 1];
      }

    for (int i = 1; i < n; i++) {

      for (int j = 1; j < n; j++) {
        for (int a = m + 1; a < n; a++) {
          cout << j - a << endl;
          if (dp[i][j] - (dp[i][j - a] + dp[i - a][j] - dp[i - a][j - a]) ==
              a * a)
            m = a;
        }
      }
    }
    cout << m << endl;
  }
}
Problem p00092 (C++) — buggy submission, verdict: Runtime Error

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

int isSquare(string map[], int x, int y, int size) {
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      int nx = x + j, ny = y + i;
      if (nx >= map[0].length() || ny >= map[0].length())
        return 0;
      if (map[ny][nx] == '*')
        return 0;
    }
  }
  return 1;
}

int main() {
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    string map[n];
    getchar();
    for (int i = 0; i < n; i++) {
      getline(cin, map[i]);
    }
    int max = 0;

    for (int s = 1; s <= n; s++) {
      bool flag = false;
      for (int i = 0; !flag && i <= n - s; i++) {
        for (int j = 0; !flag && j <= n - s; j++) {
          if (isSquare(map, j, i, s)) {
            max = s;
            flag = true;
          }
        }
      }
      if (!flag)
        break;
    }
    cout << max << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int isSquare(string map[], int x, int y, int size) {
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      int nx = x + j, ny = y + i;
      if (nx >= map[0].length() || ny >= map[0].length())
        return 0;
      if (map[ny][nx] == '*')
        return 0;
    }
  }
  return 1;
}

int main() {
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    string map[10];
    getchar();
    for (int i = 0; i < n; i++) {
      getline(cin, map[i]);
    }
    int max = 0;

    for (int s = 1; s <= n; s++) {
      bool flag = false;
      for (int i = 0; !flag && i <= n - s; i++) {
        for (int j = 0; !flag && j <= n - s; j++) {
          if (isSquare(map, j, i, s)) {
            max = s;
            flag = true;
          }
        }
      }
      if (!flag)
        break;
    }
    cout << max << endl;
  }
  return 0;
}
Problem p00092 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int H, max_;

  while (true) {
    max_ = 0;

    cin >> H;

    if (H == 0) {
      break;
    }

    vector<vector<char>> c(H, vector<char>(H));

    vector<vector<int>> dp(H, vector<int>(H, 0));

    for (int i = 0; i < H; i++) {
      dp[0][i] = 1;
      dp[i][0] = 1;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < H; j++) {
        cin >> c[i][j];

        if (c[i][j] == '*') {
          dp[i][j] = 0;
        } else {
          max_ = 1;
        }
      }
    }

    for (int i = 1; i < H; i++) {
      for (int j = 1; j < H; j++) {
        if (c[i][j] == '.') {
          dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;

          max_ = max(dp[i][j], max_);
        }
      }
    }

    cout << max_ << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
  int H, W, max_;

  while (true) {
    max_ = 0;

    scanf("%d", &H);

    W = H;

    if (H == 0 && W == 0) {
      break;
    }

    vector<vector<char>> c(H, vector<char>(W));

    vector<vector<int>> dp(H, vector<int>(W, 0));

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        scanf("%c", &c[i][j]);

        if (c[i][j] == '.') {
          if (i == 0 || j == 0) {
            dp[i][j] = 1;
          }

          max_ = 1;
        }
      }
    }

    for (int i = 1; i < H; i++) {
      for (int j = 1; j < W; j++) {
        if (c[i][j] == 0) {
          dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;

          max_ = max(dp[i][j], max_);
        }
      }
    }

    printf("%d\\n", max_ * max_);
  }

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

#include <stdio.h>

int main(void) {
  static char data[1001];
  static int dp[1000][1000];
  int n;
  int i, j;
  int maxdp;

  for (;;) {
    maxdp = 0;
    scanf("%d", &n);
    if (n == 0)
      break;

    for (i = 0; i < n; i++) {
      scanf("%s", data);

      if (data[0] == '*')
        dp[i][0] = 0;
      else
        dp[i][0] = 1;

      if (i == 0) {
        for (j = 1; j < n; j++) {
          if (data[j] == '*')
            dp[0][j] = 0;
          else
            dp[0][j] = 1;
        }
      } else {
        for (j = 1; j < n; j++) {
          if (data[j] == '*') {
            dp[i][j] = 0;
            continue;
          }

          dp[i][j] = dp[i - 1][j];
          if (dp[i][j] > dp[i][j - 1])
            dp[i][j] = dp[i][j - 1];
          if (dp[i][j] > dp[i - 1][j - 1])
            dp[i][j] = dp[i - 1][j - 1];
          dp[i][j]++;

          if (maxdp < dp[i][j])
            maxdp = dp[i][j];
        }
      }
    }

    printf("%d\\n", maxdp);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int i, j;
  int x, y;
  int xlong, ylong;
  int n;
  int temp;
  int max;
  char date[1000][1001];

  for (;;) {
    x = 0;
    y = 0;
    max = 0;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
      // for(j=0;j<n+1;j++){
      scanf("%s", date[i]);
      //}
    }

    for (;;) {
      // アスタリスクの処理
      if (date[x][y] == '*') {
        x++;
        if (x == n) {
          x = 0;
          y++;
          if (y == n)
            break;
        }
      }
      // 点の時の処理
      if (date[x][y] = '.') {
        xlong = 1;
        ylong = 1;
        // Xの長さを測る
        for (;;) {
          if (date[y][x + xlong] = '.') {
            xlong++;
            if (x + xlong == n)
              break;
          }
        }
        // Yの長さを測る
        for (;;) {
          if (date[y + ylong][x] == '.') {
            ylong++;
            if (y + ylong == n - 1)
              break;
          }
        }
        // X,Yのうち小さいほうの辺の長さの正方形を作れる！
        if (xlong >= ylong)
          temp = ylong;
        else
          temp = xlong;

        if (max < temp)
          max = temp;

        x++;
        if (x == n) {
          x = 0;
          y++;
          if (y == n)
            break;
        }
      }
    }

    printf("%d", max);
  }

  //	printf("\\n");
  //
  //	for(i=0;i<10;i++){
  //		for(j=0;j<11;j++){
  //			printf("%c",date[i][j]);
  //		}
  //	}

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

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

int n;
int dp[1000][1000];
char G[1000][1000];

int solve() {
  int ans = 0;

  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (G[i][j] == '*')
        dp[i][j] = 0;
      else {
        if (i > 0 && j > 0) {

          //          dp[i][j] = min({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j -
          //          1]}) + 1;
          int a = min(dp[i - 1][j], dp[i][j - 1]);
          dp[i][j] = min(a, dp[i - 1][j - 1]) + 1;
        } else
          dp[i][j] = 1;
        ans = max(ans, dp[i][j]);
      }
    }
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);

  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> G[i][j];
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
int n;

int main(void) {
  while (cin >> n) {
    if (!n)
      break;
    char data[n][n];
    string s[n];
    for (int i = 0; i < n; ++i) {
      cin >> data[i];
    }
    int sum = 0;

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        int a = 0;
        bool flag = false;
        while (1) {
          for (int k = 0; k <= a; ++k) {
            if ((i + a) >= 1000 || (j + a) >= 1000) {
              flag = true;
              break;
            }
            if ((i + a) >= n || (j + a) >= n) {
              flag = true;
              break;
            }
            if (data[i + a][j + k] != '.' || data[i + k][j + a] != '.') {
              flag = true;
              break;
            }
          }
          if (flag)
            break;
          a++;
          sum = max(sum, a);
        }
      }
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p00092 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, j, n) for (int i = j; i < n; i++)

int N;
char data[1000][1000];
int dp[1000][1000];

int search() {
  int max = 0;
  FOR(i, 1, N) {
    FOR(j, 1, N) {
      if (data[i][j] == '*') {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = std::min({dp[i][j - 1], dp[i - 1][j - 1], dp[i - 1][j]}) + 1;
      max = dp[i][j] > max ? dp[i][j] : max;
    }
  }
  return max;
}

int main() {
  while (1) {
    std::cin >> N;
    if (N == 0)
      return 0;
    memset(dp, 0, sizeof(dp));
    rep(i, N) {
      rep(j, N) std::cin >> data[i][j];
      dp[i][0] = data[i][0] == '.' ? 1 : 0;
      dp[0][i] = data[0][i] == '.' ? 1 : 0;
    }

    std::cout << search() << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, j, n) for (int i = j; i < n; i++)

int N;
char data[1000][1000];
int dp[1000][1000];

int search() {
  int max = 0;
  FOR(i, 1, N) {
    FOR(j, 1, N) {
      int k = i;
      int l = j;
      int up = 0, left = 0;
      int previous = dp[i - 1][j - 1] + 1;

      while (k >= 0 && data[k][j] == '.') {
        ++up;
        --k;
      }
      while (l >= 0 && data[i][l] == '.') {
        ++left;
        --l;
      }
      dp[i][j] = std::min({up, left, previous});
      max = dp[i][j] > max ? dp[i][j] : max;
    }
  }

  return max;
}

int main() {
  while (1) {
    std::cin >> N;
    if (N == 0)
      return 0;
    memset(dp, 0, sizeof(dp));
    rep(i, N) {
      rep(j, N) std::cin >> data[i][j];
      dp[i][0] = data[i][0] == '.' ? 1 : 0;
      dp[0][i] = data[0][i] == '.' ? 1 : 0;
    }

    std::cout << search() << std::endl;
  }

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

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int n;
char dt[1000][1000];
int l[1000][1000], u[1000][1000];
int sq[1000][1000];

int min(int x, int y) {
  if (x < y)
    return x;
  else
    return y;
}

int max(int x, int y) {
  if (x > y)
    return x;
  else
    return y;
}

int main() {
  while (cin >> n, n) {
    rep(i, n) {
      rep(j, n) {
        cin >> dt[i][j];
        if (dt[i][j] == '.') {
          if (j > 0)
            l[i][j] = l[i][j - 1] + 1;
          else
            l[i][j] = 1;
          if (i > 0)
            u[i][j] = u[i - 1][j] + 1;
          else
            u[i][j] = 1;
          if (i == 0 || j == 0)
            sq[i][j] = 1;
        } else {
          l[i][j] = u[i][j] = sq[i][j] = 0;
        }
      }
    }
    loop(i, 1, n) {
      loop(j, 1, n) {
        sq[i][j] = min(min(l[i][j], u[i][j]), sq[i - 1][j - 1] + 1);
      }
    }
    int ans = 0;
    rep(i, n) rep(j, n) ans = max(ans, sq[i][j]);
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int min(int x, int y) {
  if (x < y)
    return x;
  else
    return y;
}

int max(int x, int y) {
  if (x > y)
    return x;
  else
    return y;
}

int main() {
  int n;
  while (cin >> n, n) {
    char dt[n][n];
    int left[n][n], up[n][n];
    int square[n][n];
    rep(i, n) {
      rep(j, n) {
        cin >> dt[i][j];
        if (dt[i][j] == '.') {
          if (j > 0)
            left[i][j] = left[i][j - 1] + 1;
          else
            left[i][j] = 1;
          if (i > 0)
            up[i][j] = up[i - 1][j] + 1;
          else
            up[i][j] = 1;
          if (i == 0 || j == 0)
            square[i][j] = 1;
        } else {
          left[i][j] = up[i][j] = square[i][j] = 0;
        }
      }
    }
    loop(i, 1, n) {
      loop(j, 1, n) {
        square[i][j] = min(min(left[i][j], up[i][j]), square[i - 1][j - 1] + 1);
      }
    }
    int ans = 0;
    rep(i, n) rep(j, n) ans = max(ans, square[i][j]);
    cout << ans << endl;
  }
  return 0;
}