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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
  while (1) {
    int ans = 0;
    int h, w;
    int c[505][505];
    char f[505][505];
    memset(c, 0, sizeof(c));
    for (int i = 0; i < 505; i++) {
      for (int j = 0; j < 505; j++) {
        f[i][j] = '\\0';
      }
    }
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> f[i][j];
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (f[i][j] == '*')
          continue;
        int x = 0;
        while (f[i][j + x] == '.')
          x++;
        c[i][j] = x;
      }
    }
    /*for(int i=0;i<h;i++)
    {
            for(int j=0;j<w;j++)
            {
                    cout << c[i][j] << ' ';
            }
            cout << endl;
    }*/
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int mi = INF;
        for (int k = 1; k < h - i + 1; k++) {
          mi = min(mi, c[i + k - 1][j]);
          ans = max(ans, k * mi);
        }
      }
    }
    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 <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
  while (1) {
    char f[505][505];
    int h, w;
    int ans = 0;
    vector<P> vec;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> f[i][j];
        vec.pb(mp(i, j));
      }
    }
    for (int i = 0; i < vec.size(); i++) {
      for (int j = i; j < vec.size(); j++) {
        bool flag = true;
        if (vec[i].sec > vec[j].sec)
          continue;
        for (int k = vec[i].fi; k <= vec[j].fi; k++) {
          for (int l = vec[i].sec; l <= vec[j].sec; l++) {
            if (f[k][l] == '*') {
              flag = false;
              goto end;
            }
          }
        }
      end:;
        if (flag) {
          ans = max(ans, (vec[j].fi - vec[i].fi + 1) *
                             (vec[j].sec - vec[i].sec + 1));
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}