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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  while (cin >> N, N) {
    vector<vector<int>> data(N + 1, vector<int>(N + 1));
    for (size_t i = 1; i < N + 1; i++) {
      for (size_t j = 1; j < N + 1; j++) {
        char c;
        cin >> c;
        if (c == '.')
          data[i][j] = 1;
      }
    }
    for (size_t i = 1; i < N + 1; i++) {
      for (size_t j = 1; j < N + 1; j++) {
        data[i][j] += data[i][j - 1];
      }
    }
    for (size_t i = 1; i < N + 1; i++) {
      for (size_t j = 1; j < N + 1; j++) {
        data[i][j] += data[i - 1][j];
      }
    }
    long long int ans = 0;
    for (size_t i = 0; i < N; i++) {
      for (size_t j = 0; j < N; j++) {
        for (size_t k = ans; i + k < N + 1 && j + k < N + 1; k++) {
          long long int num =
              data[i + k][j + k] + data[i][j] - data[i + k][j] - data[i][j + k];
          if (k * k == num && k > ans) {
            ans = k;
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main() {
  int N;
  while (cin >> N, N) {
    vector<vector<bool>> data;
    data.resize(N * 2 + 2);
    for (size_t i = 0; i < N * 2 + 2; i++) {
      data[i].resize(N + 1);
    }
    string str;
    for (size_t i = 0; i < N; i++) {
      cin >> str;
      for (size_t j = 0; j < N; j++) {
        if (str[j] == '.') {
          data[i][j] = 1;
        }
      }
    }

    int ans = 0;
    for (size_t i = 0; i < N - ans; i++) {
      for (size_t j = 0; j < N - ans; j++) {
        if (data[i][j] == 1) {
          int k = ans;
          bool f = 1;
          while (f && j + k <= N) {
            for (size_t l = 0; f && l < k; l++) {
              for (size_t m = 0; f && m < k; m++) {
                if (data[i + l][j + m] != 1) {
                  f = 0;
                }
              }
            }
            if (f && ans < k) {
              ans = k;
            }
            k++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}