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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<string> grid(n);
    REP(i, n) { cin >> grid[i]; }
    bool find = false;
    for (int size = 1; size <= n; size++) {
      find = false;
      for (int l = 0; l + size <= n; l++) {
        for (int h = 0; h + size <= n; h++) {
          bool f = true;
          for (int x = l; x < l + size; x++) {
            for (int y = h; y < h + size; y++) {
              if (grid[y][x] == '*') {
                f = false;
                break;
              }
            }
            if (!f)
              break;
          }
          if (f) {
            find = true;
            break;
          }
        }
        if (find)
          break;
      }
      if (!find) {
        cout << size - 1 << endl;
        find = true;
        break;
      } else if (size == n) {
        cout << n << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int max_l(string s) {
  int r = 0, ret = 0;
  REP(i, s.size()) {
    if (s[i] == '*') {
      ret = max(ret, r);
      r = 0;
    } else {
      r++;
    }
  }
  ret = max(ret, r);
  return ret;
}
int max_l(int i, vector<string> s) {
  int r = 0, ret = 0;
  REP(j, s.size()) {
    if (s[j][i] == '*') {
      ret = max(ret, r);
      r = 0;
    } else {
      r++;
    }
  }
  ret = max(ret, r);
  return ret;
}

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int m = 0;
    vector<string> grid(n);
    REP(i, n) { cin >> grid[i]; }
    REP(i, grid.size()) { m = max(m, max_l(grid[i])); }
    REP(i, grid[0].size()) { m = max(m, max_l(i, grid)); }
    bool out = false;
    for (int i = m; i > 0; i--) {
      for (int j = 0; i + j <= n; j++) {
        for (int k = 0; i + k <= n; k++) {
          bool f = true;
          for (int x = j; x < i + j; x++) {
            for (int y = k; y < i + k; y++) {
              if (grid[y][x] == '*') {
                f = false;
                break;
              }
            }
            if (!f)
              break;
          }
          if (f) {
            cout << i << endl;
            out = true;
            break;
          }
        }
        if (out)
          break;
      }
      if (out)
        break;
    }
  }
  return 0;
}