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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = b; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
char board[1100][1100];
int dp[1100][1100]; //
int main() {
  int n;
  while (cin >> n, n) {
    bool fi = false;

    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        cin >> board[i][j];
        dp[i][j] = 0;
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (board[i][j] == '*') {
          dp[i][j] = 0;
        } else {
          dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
          if (dp[i][j] > ans) {
            ans = dp[i][j];
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = b; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
char board[1100][1100];
int main() {
  int n;
  while (cin >> n, n) {
    bool fi = false;
    rep(i, n) {
      rep(j, n) {
        cin >> board[i][j];
        if (board[i][j] == '.') {
          fi = true;
        }
      }
    }
    if (!fi) {
      cout << 0 << endl;
      continue;
    }
    bool suc = false;
    for (int s = n; s >= 1 && !suc; s--) {          // 正方形のs*s
      for (int i = 0; i + s - 1 < n && !suc; i++) { // 正方形の左上
        for (int j = 0; j + s - 1 < n && !suc; j++) {
          if (board[i][j] == '.') {
            bool flag = true;
            for (int y = 0; y <= s - 1 && flag; y++) {
              for (int x = 0; x <= s - 1 && flag; x++) {
                int ty = i + y;
                int tx = j + x;
                if (board[ty][tx] == '*') {
                  flag = false;
                  j += x;
                  break;
                }
              }
            }
            if (flag) {
              suc = true;
              cout << s << endl;
            }
          }
        }
      }
    }
    if (!suc) {
      cout << 0 << endl;
    }
  }
  return 0;
}