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

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second

int n;
vector<string> table;
vector<vector<ll>> dp;

int main() {
  while (cin >> n && n) {
    table.clear();
    dp.clear();
    table.resize(n);
    dp.resize(n);
    REP(i, n) {
      table[i].resize(n);
      dp[i].resize(n);
    }
    REP(i, n) {
      string s;
      cin >> s;
      REP(j, n) {
        table[i][j] = s[j];
        if (i == 0 || j == 0)
          dp[i][j] = (s[j] == '.');
      }
    }
    FOR(i, 1, n) {
      FOR(j, 1, n) {
        if (table[i][j] == '*')
          continue;
        dp[i][j] = min(dp[i][j - 1], min(dp[i - 1][j - 1], dp[i - 1][j])) + 1;
      }
    }
    ll ans = 0;
    REP(i, n) {
      REP(j, n) { ans = max(ans, dp[i][j]); }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
char table[1010][1010];
int co[1010][1010];

int main() {
  while (cin >> n && n) {
    REP(i, n) REP(j, n) cin >> table[i][j];
    REP(i, n) {
      REP(j, n) {
        if (table[i][j] == '*') {
          co[i][j] = 0;
        } else {
          if (j == 0)
            co[i][j] = 1;
          else
            co[i][j] = co[i][j - 1] + 1;
        }
      }
    }
    REP(i, n) {
      if (i == 0)
        continue;
      REP(j, n) {
        if (co[i][j] == 0)
          continue;
        co[i][j] += co[i - 1][j];
      }
    }

    // REP(i, n){
    //	REP(j, n){
    //		printf("%3d", co[i][j]);
    //	}
    //	cout << endl;
    // }
    int ans = 0;
    REP(i, n) {
      REP(j, n) {
        FOR(z, 1, n - max(i, j) + 1) {
          bool f = 1;
          REP(k, z) {
            REP(l, z) {
              if (co[i + k][j + l] <= k * l)
                f = 0;
            }
          }
          if (f)
            ans = max(ans, (int)z);
        }
      }
    }
    cout << ans << endl;
  }
}