Problem:
正方形探索
縦に
n
行、横に
n
列並べられた、合計
n × n
のマス目があります。いくつかのマス目には印がついています。各マス目の印の状態を読み込み、印のついていないマス目だけからなる最大の正方形の辺の長さを出力として表示するプログラムを作成してください。
たとえば各データセットで以下のようなデータが与えられます。
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
入力データの一行が、一行のマス目を表現します。入力データの文字列のうち、.（ピリオド）は印のついていないマス目、*（アスタリスク）は印のついているマス目を示しています。
上記の例では、下図の 0 で示される正方形が最大となります。
...*....**
..........
**....**..
...00000*.
..*00000..
...00000..
.*.00000..
...00000..
....*..***
.*....*...
よって、5 と出力すれば正解になります。
なお、すべてのマス目に印がついている場合には、0 を出力してください。
Input
上記形式で複数のデータセットが与えられます。
n
が 0 のとき入力の最後とします。
n
は 1000 以下とします。入力データの文字列には、ピリオド、アスタリスク、改行以外の文字は含まれません。データセットの数は 50 を超えません。
Output
各データセットに対し、最大の正方形の辺の長さ（整数）を１行に出力して下さい。
Sample Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output for the Sample Input
5
3

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

#define ll long long
using namespace std;

int main() {
    ll n;
    while (cin>>n) {
        if(n==0){
            return 0;
        }
        char a;
        vector<vector<ll>> A(n);
        for (ll i = 0; i < n; ++i) {
            A[i].resize(n);
            for (ll j = 0; j < n; ++j) {
                cin >> a;
                A[i][j] = (a == '.');
            }
        }
        vector<vector<ll>> Left(n);
        vector<vector<ll>> Up(n);
        for (ll i = 0; i < n; ++i) {
            Left[i].resize(n);
            Left[i][0] = A[i][0];
            for (ll j = 1; j < n; ++j) {
                if (A[i][j] == 0) {
                    Left[i][j] = 0;
                } else {
                    Left[i][j] = 1 + Left[i][j - 1];
                }
            }
        }
        for(ll i=0;i<n;++i){
            Up[i].resize(n);
        }
        for (ll i = 0; i < n; ++i) {
            Up[0][i] = A[0][i];
            for (ll j = 1; j < n; ++j) {
                if (A[j][i] == 0) {
                    Up[j][i] = 0;
                } else {
                    Up[j][i] = 1 + Up[j - 1][i];
                }
            }
        }
        vector<vector<ll>> Dp(n);
        for (ll i=0;i<n;++i) {
            Dp[i].resize(n);
        }
        for (ll i = 0; i < n; ++i) {
            Dp[0][i] = A[0][i];
            Dp[i][0] = A[i][0];
        }
        for (ll i = 1; i < n; ++i) {
            for (ll j = 1; j < n; ++j) {
                if (Dp[i - 1][j - 1] < Left[i][j] and Dp[i - 1][j - 1] < Up[i][j]) {
                    Dp[i][j] = 1 + Dp[i - 1][j - 1];
                } else {
                    Dp[i][j] = min(Left[i][j], Up[i][j]);
                }
            }
        }
        ll ans = 0;
        for (ll i = 0; i < n; ++i) {
            for (ll j = 0; j < n; ++j) {
                ans = max(ans, Dp[i][j]);
            }
        }
        cout << ans << "\n";
    }
}
accuracy: 1
time_ms: 140
memory_kb: 34744
final_rank: 19

code_snippet: #pragma region Macros

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2")

#include <bits/extc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using namespace __gnu_pbds;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Bdouble = mp::number<mp::cpp_dec_float<256>>;
// Bdouble Beps = 0.00000000000000000000000000000001; // 1e-32
// const bool equals(Bdouble a, Bdouble b) { return mp::fabs(a - b) < Beps; }

#define pb emplace_back
#define int ll
#define endl '\n'
// #define unordered_map<int, int> gp_hash_table<int, int, custom_hash> 

#define sqrt __builtin_sqrtl
#define cbrt __builtin_cbrtl
#define hypot __builtin_hypotl

#define next asdnext
#define prev asdprev

using ll = long long;
using ld = long double;
const ld PI = acosl(-1);
const int INF = 1 << 30;
const ll INFL = 1LL << 61;
// const int MOD = 998244353;
const int MOD = 1000000007;

const ld EPS = 1e-10;
const bool equals(ld a, ld b) { return fabs((a) - (b)) < EPS; }

const vector<int> dx = {0, 1, 0, -1, 1, 1, -1, -1}; // → ↓ ← ↑ ↘ ↙ ↖ ↗
const vector<int> dy = {1, 0, -1, 0, 1, -1, -1, 1};

struct Edge {
    int from, to, cost;
    Edge() : from(-1), to(-1), cost(-1) {}
    Edge(int to, int cost) : to(to), cost(cost) {}
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator ==(const Edge& e) {
        return this->from == e.from && this->to == e.to && this->cost == e.cost;
    }
    bool operator !=(const Edge& e) {
        return this->from != e.from or this->to != e.to or this->cost != e.cost;
    }
};

chrono::system_clock::time_point start;
__attribute__((constructor))
void constructor() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    start = chrono::system_clock::now();
}

random_device seed_gen;
mt19937_64 rng(seed_gen());
uniform_int_distribution<int> dist_x(0, 1e9);
struct RNG {
    unsigned Int(unsigned l, unsigned r) {
        return dist_x(rng) % (r - l + 1) + l;
    }
    ld Double() {
        return ld(dist_x(rng)) / 1e9;
    }
} rnd;

using i64 = ll;
// using i64 = uint64_t;
// bit演算, x==0の場合は例外処理した方がよさそう. 区間は [l, r)
i64 lrmask(i64 l, i64 r) { return (1LL << r) - (1LL << l); }
i64 sub_bit(i64 x, i64 l, i64 r) { i64 b = x & ((1LL << r) - (1LL << l)); return b >> l; } // r溢れ可
i64 bit_width(i64 x) { return 64 - __builtin_clzll(x) + (x == 0); }

i64 popcount(i64 x) { return __builtin_popcountll(x); }
i64 popcount(i64 x, i64 l, i64 r) { return __builtin_popcountll(sub_bit(x, l, r)); }
i64 unpopcount(i64 x) { return bit_width(x) - __builtin_popcountll(x); }
i64 unpopcount(i64 x, i64 l, i64 r) { return r - l - __builtin_popcountll(sub_bit(x, l, r)); }
bool is_pow2(i64 x) { return __builtin_popcountll(x) == 1; }

i64 top_bit(i64 x) { return 63 - __builtin_clzll(x);} // 2^kの位 (x > 0)
i64 bot_bit(i64 x) { return __builtin_ctz(x);} // 2^kの位 (x > 0)
// i64 next_bit(i64 x, i64 k) { return 0; }
// i64 prev_bit(i64 x, i64 k) { return 0; }
// i64 kth_bit(i64 x, i64 k) { return 0; }
i64 MSB(i64 x) { if (x == 0) return 0; return 1LL << (63 - __builtin_clzll(x)); } // mask
i64 LSB(i64 x) { return (x & -x); } // mask

i64 countl_zero(i64 x) { return __builtin_clzll(x); }
i64 countl_one(i64 x) {
    i64 ret = 0, k = 63 - __builtin_clzll(x);
    while (k != -1 && (x & (1LL << k))) { k--; ret++; }
    return ret;
}
i64 countr_zero(i64 x) { return __builtin_ctzll(x); } // x==0のとき64が返ることに注意
i64 countr_one(i64 x) { i64 ret = 0; while (x & 1) { x >>= 1; ret++; } return ret; }

i64 floor_log2(i64 x) { if (x == 0) return 0; return 63 - __builtin_clzll(x); }
i64 bit_floor(i64 x) { if (x == 0) return 0; return 1LL << (63 - __builtin_clzll(x)); } // MSBと同じ
i64 ceil_log2(i64 x) { if (x == 0) return 0; return 64 - __builtin_clzll(x - 1); }
i64 bit_ceil(i64 x) { if (x == 0) return 0; return 1LL << (64 - __builtin_clzll(x - 1)); }

i64 rotl(i64 x, i64 k) { // 有効bit内でrotate. オーバーフロー注意
    i64 w = bit_width(x); k %= w;
    return ((x << k) | (x >> (w - k))) & ((1LL << w) - 1);
}
// i64 rotl(i64 x, i64 l, i64 m, i64 r) {}
i64 rotr(i64 x, i64 k) {
    i64 w = bit_width(x); k %= w;
    return ((x >> k) | (x << (w - k))) & ((1LL << w) - 1);
}
// i64 rotr(i64 x, i64 l, i64 m, i64 r) {}
i64 bit_reverse(i64 x) { // 有効bit内で左右反転
    i64 r = 0, w = bit_width(x);
    for (i64 i = 0; i < w; i++) r |= ((x >> i) & 1) << (w - i - 1);
    return r;
}
// i64 bit_reverse(i64 x, i64 l, i64 r) { return 0; }

bool is_palindrome(i64 x) { return x == bit_reverse(x); }
bool is_palindrome(i64 x, i64 l, i64 r) { i64 b = sub_bit(x, l, r); return b == bit_reverse(b); }
i64 concat(i64 a, i64 b) { return (a << bit_width(b)) | b; } // オーバーフロー注意
i64 erase(i64 x, i64 l, i64 r) { return x>>r<<l | x&(1LL<<l - 1); } // [l, r) をカット

i64 hamming(i64 a, i64 b) { return __builtin_popcountll(a ^ b); }
i64 hamming(i64 a, i64 b, i64 l, i64 r) { return __builtin_popcountll(sub_bit(a, l, r) ^ sub_bit(b, l, r)); }
i64 compcount(i64 x) { return (__builtin_popcountll(x ^ (x >> 1)) + (x & 1)) / 2; }
i64 compcount2(i64 x) { return compcount(x & (x >> 1)); } // 長さ2以上の連結成分の個数
i64 adjacount(i64 x) { return __builtin_popcountll(x & (x >> 1)); } // 隣接する1のペアの個数

i64 next_combination(i64 x) {
    i64 t = x | (x - 1); return (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(x) + 1));
}


__int128_t POW(__int128_t x, int n) {
    __int128_t ret = 1;
    assert(n >= 0);
    if (x == 1 or n == 0) ret = 1;
    else if (x == -1 && n % 2 == 0) ret = 1; 
    else if (x == -1) ret = -1; 
    else if (n % 2 == 0) {
        assert(x < INFL);
        ret = POW(x * x, n / 2);
    } else {
        assert(x < INFL);
        ret = x * POW(x, n - 1);
    }
    return ret;
}
int per(int x, int y) { // x = qy + r (0 <= r < y) を満たすq
    assert(y != 0);
    if (x >= 0 && y > 0) return x / y;
    if (x >= 0 && y < 0) return x / y - (x % y < 0);
    if (x < 0 && y < 0) return x / y + (x % y < 0);
    return x / y - (x % y < 0); //  (x < 0 && y > 0) 
}
int mod(int x, int y) { // x = qy + r (0 <= r < y) を満たすr
    assert(y != 0);
    if (x >= 0) return x % y;
    __int128_t ret = x % y; // (x < 0)
    ret += (__int128_t)abs(y) * INFL;
    ret %= abs(y);
    return ret;
}
int floor(int x, int y) { // (ld)x / y 以下の最大の整数
    assert(y != 0);
    if (y < 0) x = -x, y = -y;
    return x >= 0 ? x / y : (x + 1) / y - 1;
}
int ceil(int x, int y) { // (ld)x / y 以上の最小の整数
    assert(y != 0);
    if (y < 0) x = -x, y = -y;
    return x > 0 ? (x - 1) / y + 1 : x / y;
}
int round(int x, int y) {
    assert(y != 0);
    return (x * 2 + y) / (y * 2);
}
int round(int x, int y, int k) { // (ld)(x/y)を10^kの位に関して四捨五入
    assert(y != 0); // TODO
    return INF;
}
int round2(int x, int y) { // 五捨五超入 // 未verify
    assert(y != 0);
    if (y < 0) y = -y, x = -x;
    int z = z / y;
    if ((z * 2 + 1) * y <= y * 2) z++;
    return z;
}
// int round(ld x, int k) { // xを10^kの位に関して四捨五入
// }
// int floor(ld x, int k) { // xを10^kの位に関してflooring
// }
// int ceil(ld x, int k) { // xを10^kの位に関してceiling
// }
// int kth(int x, int y, int k) { // x / yの10^kの位の桁
// }
int floor(ld x, ld y) { // 誤差対策TODO
    assert(!equals(y, 0));
    return floor(x / y);
    // floor(x) = ceil(x - 1) という話も
}
int ceil(ld x, ld y) { // 誤差対策TODO // ceil(p/q) = -floor(-(p/q))らしい
    assert(!equals(y, 0));
    return ceil(x / y);
    // ceil(x) = floor(x + 1)
}
int perl(ld x, ld y) { // x = qy + r (0 <= r < y, qは整数) を満たす q
    // 未verify. 誤差対策TODO. EPS外してもいいかも。
    assert(!equals(y, 0));
    if (x >= 0 && y > 0) return floor(x / y)+EPS;
    if (x >= 0 && y < 0) return -floor(x / fabs(y));
    if (x < 0 && y < 0) return floor(x / y) + (x - floor(x/y)*y < -EPS);
    return floor(x / y) - (x - floor(x/y)*y < -EPS); //  (x < 0 && y > 0) 
}
ld modl(ld x, ld y) { // x = qy + r (0 <= r < y, qは整数) を満たす r
    // 未verify. 誤差対策TODO. -0.0が返りうる。
    assert(!equals(y, 0));
    if (x >= 0) return x - fabs(y)*fabs(per(x, y));
    return x - fabs(y)*floor(x, fabs(y));
}
int seisuu(ld x) { return (int)x; } // 整数部分. 誤差対策TODO
int modf(ld x) {
	if (x < 0) return ceill(x);
	else return floorl(x);
}
// 正なら+EPS, 負なら-EPSしてから、文字列に直して小数点以下を捨てる?
int seisuu(int x, int y) {
    assert(y != 0);
    return x / y;
}
int seisuu(ld x, ld y) { // 誤差対策TODO
    assert(!equals(y, 0));
    return (int)(x / y);
}

template <class T> pair<T, T> max(const pair<T, T> &a, const pair<T, T> &b) {
    if (a.first > b.first or a.first == b.first && a.second > b.second) return a;
    return b;
}
template <class T> pair<T, T> min(const pair<T, T> &a, const pair<T, T> &b) {
    if (a.first < b.first or a.first == b.first && a.second < b.second) return a;
    return b;
}

template <class T> bool chmax(T &a, const T& b) {
    if (a < b) { a = b; return true; } return false;
}
template <class T> bool chmin(T &a, const T& b) {
    if (a > b) { a = b; return true; } return false;
}
template <class T> T mid(T a, T b, T c) { // 誤差対策TODO
    return a + b + c - max({a, b, c}) - min({a, b, c});
}
template <class T> void Sort(T &a, T &b, bool rev = false) { 
    if (rev == false) {  // TODO テンプレート引数
        if (a > b) swap(a, b);
    } else {
        if (b > a) swap(b, a);
    }
}
template <class T> void sort(T &a, T &b, T &c, bool rev = false) {
    if (rev == false) { 
        if (a > b) swap(a, b); if (a > c) swap(a, c); if (b > c) swap(b, c);
    } else {
        if (c > b) swap(c, b); if (c > a) swap(c, a); if (b > a) swap(b, a);
    }
}
template <class T> void sort(T &a, T &b, T &c, T &d, bool rev = false) {
    if (rev == false) { 
        if (a > b) swap(a, b); if (a > c) swap(a, c);  if (a > d) swap(a, d);
        if (b > c) swap(b, c); if (b > d) swap(b, d); if (c > d) swap(c, d);
    } else {
        if (d > c) swap(d, c); if (d > b) swap(d, b); if (d > a) swap(d, a);
        if (c > b) swap(c, b); if (c > a) swap(c, a); if (b > a) swap(b, a);
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

class Compress {
public:
    int sz = 0;
    // gp_hash_table<int, int, custom_hash> Z, UZ;
    unordered_map<int, int> Z;    // 元の値 -> 圧縮した値
    unordered_map<int, int> UZ;   // 圧縮した値 -> 元の値

    Compress(const vector<int> &V, int base = 0) {
        this->sz = base;
        set<int> s(V.begin(), V.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }
    
    Compress(const vector<int> &V1, const vector<int> &V2, int base = 0) {
        this->sz = base;
        vector<int> V3 = V2;
        V3.insert(V3.end(), V1.begin(), V1.end());
        set<int> s(V3.begin(), V3.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }

    Compress(const vector<int> &V1, const vector<int> &V2, const vector<int> &V3, int base = 0) {
        this->sz = base;
        vector<int> V4 = V1;
        V4.insert(V4.end(), V2.begin(), V2.end());
        V4.insert(V4.end(), V3.begin(), V3.end());
        set<int> s(V4.begin(), V4.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }

    Compress(const vector<int> &V1, const vector<int> &V2,
            const vector<int> &V3, const vector<int> &V4, int base = 0) {
        this->sz = base;
        vector<int> V5 = V1;
        V5.insert(V5.end(), V2.begin(), V2.end());
        V5.insert(V5.end(), V3.begin(), V3.end());
        V5.insert(V5.end(), V4.begin(), V4.end());
        set<int> s(V5.begin(), V5.end());

        for (int x : s) {
            this->Z[x] = this->sz;
            this->UZ[this->sz] = x;
            this->sz++;
        }
    }

    vector<int> zip(const vector<int> &V) {
        vector<int> ret = V;
        for (int i = 0; i < (int)V.size(); i++) {
            ret[i] = Z[ret[i]];
        }
        return ret;
    }

    vector<int> unzip(const vector<int> &V) {
        vector<int> ret = V;
        for (int i = 0; i < (int)V.size(); i++) {
            ret[i] = UZ[ret[i]];
        }
        return ret;
    }

    int size() { return sz; }

    int encode(int x) { return Z[x]; }
    int decode(int x) {
        if (UZ.find(x) == UZ.end()) return -1; // xが元の配列に存在しないとき
        return UZ[x];
    }
};

class UnionFind {
public:
	UnionFind() = default;
    UnionFind(int N) : par(N), sz(N, 1) {
        iota(par.begin(), par.end(), 0);
    }
	int root(int x) {
		if (par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
        if (rx == ry) return false;
		if (sz[rx] < sz[ry]) swap(rx, ry);
		sz[rx] += sz[ry];
		par[ry] = rx;
        return true;
	}
	bool issame(int x, int y) { return (root(x) == root(y)); }
	int size(int x) { return sz[root(x)]; }
    vector<vector<int>> groups(int N) {
        vector<vector<int>> G(N);
        for (int x = 0; x < N; x++) {
            G[root(x)].push_back(x);
        }
		G.erase( remove_if(G.begin(), G.end(),
            [&](const vector<int>& V) { return V.empty(); }), G.end());
        return G;
    }
private:
	vector<int> par, sz;
};

template<typename T>
struct BIT {
    int N;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int N_, int x = 0) {
        N = N_ + 1;
        bit[0].assign(N, 0); bit[1].assign(N, 0);
        if (x != 0) {
            for (int i = 0; i < N; i++) add(i, x);
        }
    }
    BIT(const vector<int> &A) {
        N = A.size() + 1;
        bit[0].assign(N, 0); bit[1].assign(N, 0);
        for (int i = 0; i < (int)A.size(); i++) add(i, A[i]);
    }
    void add_sub(int p, int i, T x) {
        while (i < N) { bit[p][i] += x; i += (i & -i); }
    }
    void add(int l, int r, T x) {
        add_sub(0, l + 1, -x * l); add_sub(0, r + 1, x * r);
        add_sub(1, l + 1, x); add_sub(1, r + 1, -x);
    }
    void add(int i, T x) { add(i, i + 1, x); }
    T sum_sub(int p, int i) {
        T ret = 0;
        while (i > 0) { ret += bit[p][i]; i -= (i & -i); }
        return ret;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
    T sum(int l, int r) { return sum(r) - sum(l); }
    T get(int i) { return sum(i, i + 1); }
    void set(int i, T x) { T s = get(i); add(i, -s + x); }
};

template<int mod> class Modint {
public:
    int val = 0;
    Modint(int x = 0) { while (x < 0) x += mod; val = x % mod; }
    Modint(const Modint &r) { val = r.val; }

    Modint operator -() { return Modint(-val); } // 単項
    Modint operator +(const Modint &r) { return Modint(*this) += r; }
    Modint operator +(const int &q) { Modint r(q); return Modint(*this) += r; }
    Modint operator -(const Modint &r) { return Modint(*this) -= r; }
    Modint operator -(const int &q) { Modint r(q); return Modint(*this) -= r; }
    Modint operator *(const Modint &r) { return Modint(*this) *= r; }
    Modint operator *(const int &q) { Modint r(q); return Modint(*this) *= r; }
    Modint operator /(const Modint &r) { return Modint(*this) /= r; }
    Modint operator /(const int &q) { Modint r(q); return Modint(*this) /= r; }
    
    Modint& operator ++() { val++; if (val >= mod) val -= mod; return *this; } // 前置
    Modint operator ++(signed) { ++*this; return *this; } // 後置
    Modint& operator --() { val--; if (val < 0) val += mod; return *this; }
    Modint operator --(signed) { --*this; return *this; }
    Modint &operator +=(const Modint &r) { val += r.val; if (val >= mod) val -= mod; return *this; }
    Modint &operator +=(const int &q) { Modint r(q); val += r.val; if (val >= mod) val -= mod; return *this; }
    Modint &operator -=(const Modint &r) { if (val < r.val) val += mod; val -= r.val; return *this; }
    Modint &operator -=(const int &q) { Modint r(q);  if (val < r.val) val += mod; val -= r.val; return *this; }
    Modint &operator *=(const Modint &r) { val = val * r.val % mod; return *this; }
    Modint &operator *=(const int &q) { Modint r(q); val = val * r.val % mod; return *this; }
    Modint &operator /=(const Modint &r) {
        int a = r.val, b = mod, u = 1, v = 0;
        while (b) {int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v);}
        val = val * u % mod; if (val < 0) val += mod;
        return *this;
    }
    Modint &operator /=(const int &q) {
        Modint r(q); int a = r.val, b = mod, u = 1, v = 0;
        while (b) {int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v);}
        val = val * u % mod; if (val < 0) val += mod;
        return *this;
    }
    bool operator ==(const Modint& r) { return this -> val == r.val; }
    bool operator <(const Modint& r) { return this -> val < r.val; }
    bool operator >(const Modint& r) { return this -> val > r.val; }
    bool operator !=(const Modint& r) { return this -> val != r.val; }
};

using mint = Modint<MOD>;

istream &operator >>(istream &is, mint& x) {
    int t; is >> t; x = t; return (is);
}
ostream &operator <<(ostream &os, const mint& x) {
    return os << x.val;
}
mint modpow(const mint &x, int n) {
    if (n < 0) return (mint)1 / modpow(x, -n); // 未verify
    assert(n >= 0);
    if (n == 0) return 1;
    mint t = modpow(x, n / 2);
    t = t * t;
    if (n & 1) t = t * x;
    return t;
}

int modpow(__int128_t x, int n, int mod) {
    assert(n >= 0 && mod > 0); // TODO: n <= -1
    __int128_t ret = 1;
    while (n > 0) {
        if (n % 2 == 1) ret = ret * x % mod;
        x = x * x % mod;
        n /= 2;
    }
    return ret;
}
int modinv(__int128_t x, int mod) {
    assert(mod > 0);
    // assert(x > 0);
    if (x == 1 or x == 0) return 1;
    return mod - modinv(mod % x, mod) * (mod / x) % mod;
}

istream &operator >>(istream &is, __int128_t& x) {
    string S; is >> S;
    __int128_t ret = 0;
    int f = 1;
    if (S[0] == '-') f = -1; 
    for (int i = 0; i < S.length(); i++)
        if ('0' <= S[i] && S[i] <= '9')
            ret = ret * 10 + S[i] - '0';
    x = ret * f;
    return (is);
}
ostream &operator <<(ostream &os, __int128_t x) {
    ostream::sentry s(os);
    if (s) {
        __uint128_t tmp = x < 0 ? -x : x;
        char buffer[128]; char *d = end(buffer);
        do {
            --d; *d = "0123456789"[tmp % 10]; tmp /= 10;
        } while (tmp != 0);
        if (x < 0) { --d; *d = '-'; }
        int len = end(buffer) - d;
        if (os.rdbuf()->sputn(d, len) != len) os.setstate(ios_base::badbit);
    }
    return os;
}

__int128_t stoll(string &S) {
    __int128_t ret = 0; int f = 1;
    if (S[0] == '-') f = -1; 
    for (int i = 0; i < S.length(); i++)
        if ('0' <= S[i] && S[i] <= '9') ret = ret * 10 + S[i] - '0';
    return ret * f;
}
__int128_t gcd(__int128_t a, __int128_t b) { return b ? gcd(b, a % b) : a; }
__int128_t lcm(__int128_t a, __int128_t b) {
    return a / gcd(a, b) * b;
    // lcmが__int128_tに収まる必要あり
}

string to_string(ld x, int k) { // xの小数第k位までをstring化する
    assert(k >= 0);
    stringstream ss;
    ss << setprecision(k + 2) << x;
    string s = ss.str();
    if (s.find('.') == string::npos) s += '.';
    int pos = s.find('.');
    for (int i = 0; k >= (int)s.size() - 1 - pos; i++) s += '0';
    s.pop_back();
    if (s.back() == '.') s.pop_back();
    return s;

    // stringstream ss; // 第k+1位を四捨五入して第k位まで返す
    // ss << setprecision(k + 1) << x;
    // string s = ss.str();
    // if (s.find('.') == string::npos) s += '.';
    // int pos = s.find('.');
    // for (int i = 0; k > (int)s.size() - 1 - pos; i++) s += '0';
    // if (s.back() == '.') s.pop_back();
    // return s;
}
string to_string(__int128_t x) {
    string ret = "";
    if (x < 0) { ret += "-"; x *= -1; }
    while (x) { ret += (char)('0' + x % 10); x /= 10; }
    reverse(ret.begin(), ret.end());
    return ret;
}
string to_string(char c) { string s = ""; s += c; return s; }

template<class T> size_t HashCombine(const size_t seed,const T &v) {
    return seed^(hash<T>()(v)+0x9e3779b9+(seed<<6)+(seed>>2));
}
template<class T,class S> struct hash<pair<T,S>>{
    size_t operator()(const pair<T,S> &keyval) const noexcept {
        return HashCombine(hash<T>()(keyval.first), keyval.second);
    }
};
template<class T> struct hash<vector<T>>{
    size_t operator()(const vector<T> &keyval) const noexcept {
        size_t s=0;
        for (auto&& v: keyval) s=HashCombine(s,v);
        return s;
    }
};
template<int N> struct HashTupleCore{
    template<class Tuple> size_t operator()(const Tuple &keyval) const noexcept{
        size_t s=HashTupleCore<N-1>()(keyval);
        return HashCombine(s,get<N-1>(keyval));
    }
};
template <> struct HashTupleCore<0>{
    template<class Tuple> size_t operator()(const Tuple &keyval) const noexcept{ return 0; }
};
template<class... Args> struct hash<tuple<Args...>>{
    size_t operator()(const tuple<Args...> &keyval) const noexcept {
        return HashTupleCore<tuple_size<tuple<Args...>>::value>()(keyval);
    }
};

vector<mint> _fac, _finv, _inv;
void COMinit(int N) {
    _fac.resize(N + 1); _finv.resize(N + 1);  _inv.resize(N + 1);
    _fac[0] = _fac[1] = 1; _finv[0] = _finv[1] = 1; _inv[1] = 1;
    for (int i = 2; i <= N; i++) {
        _fac[i] = _fac[i-1] * mint(i);
        _inv[i] = -_inv[MOD % i] * mint(MOD / i);
        _finv[i] = _finv[i - 1] * _inv[i];
    }
}

mint FAC(int N) {
    if (N < 0) return 0; return _fac[N];
}
mint COM(int N, int K) {
    if (N < K) return 0; if (N < 0 or K < 0) return 0;
    return _fac[N] * _finv[K] * _finv[N - K];
}
mint PERM(int N, int K) {
    if (N < K) return 0; if (N < 0 or K < 0) return 0;
    return _fac[N] *  _finv[N - K];
}
mint NHK(int N, int K) { // initのサイズに注意
    if (N == 0 && K == 0)  return 1;
    return COM(N + K - 1, K);
}

#pragma endregion

vector<string> split_str(string S, char c) {
    vector<string> ret;
    stringstream ss;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == c) {
            ret.pb(ss.str());
            ss.str("");
            ss.clear();
        } else {
            ss << S[i];
        }
    }
    ret.pb(ss.str());
    return ret;
}

using T = ld;
T calc_revpo(vector<string> &S) {
    int N = S.size();
    vector<T> st;
    for (int i = 0; i < N; i++) {
        if (S[i] == "+") {
            T b = st.back();
            st.pop_back();
            T a = st.back();
            st.pop_back();
            st.pb(a + b);
        } else if (S[i] == "-") {
            T b = st.back();
            st.pop_back();
            T a = st.back();
            st.pop_back();
            st.pb(a - b);
        } else if (S[i] == "*") {
            T b = st.back();
            st.pop_back();
            T a = st.back();
            st.pop_back();
            st.pb(a * b);
        } else if (S[i] == "/") {
            T b = st.back();
            st.pop_back();
            T a = st.back();
            st.pop_back();
            if (b == 0) return -1; // ゼロ除算
            st.pb(a / b);
        } else st.pb(stoll(S[i]));
    }
    return st.back();
}

signed main() {
	int N;
	while (cin >> N, N) {
        int H = N, W = N;
        vector<vector<int>> S(H, vector<int>(W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                char c;
                cin >> c;
                if (c == '*') {
                    S[i][j] = 1;
                }
            }
        }

        // 左上(0, 0), 右下(i, j)の長方形領域にある最大正方形の大きさ
        // dp[i][j]は ←　↖ ↑　の最小値+1, ただし壁マスがひとつでもあるなら1
        vector<vector<int>> dp(H, vector<int>(W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (S[i][j] == 1) continue;
                int m = INFL;
                if (i == 0 or j == 0) m = 0;
                if (i - 1 >= 0 && j - 1 >= 0) m = min(m, dp[i - 1][j - 1]);
                if (i - 1 >= 0) m = min(m, dp[i - 1][j]);
                if (j - 1 >= 0) m = min(m, dp[i][j - 1]);
                dp[i][j] = m + 1;
            }
        }

        int ans = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ans = max(ans, dp[i][j]);
            }
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 18976
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;cin>>n;
        if(n==0){
            return(0);
        }
        string s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        vector<vector<int>>t(n,vector<int>(n,0));
        int k=0;
        for(int i=0;i<n;i++){
            if(s[0][i]=='.'){
                t[0][i]=1;
                k=1;
            }
            if(s[i][0]=='.'){
                t[i][0]=1;
            }
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<n;j++){
                if(s[i][j]=='.'){
                    t[i][j]=min({t[i-1][j],t[i][j-1],t[i-1][j-1]});
                    t[i][j]++;
                    k=max(k,t[i][j]);
                }
            }
        }
        cout<<k<<"\n";
    }
}
accuracy: 1
time_ms: 50
memory_kb: 9072
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;cin>>n;
        if(n==0){
            return(0);
        }
        string s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        vector<vector<int>>a(n,vector<int>(n,0));
        for(int i=0;i<n;i++){
            if(s[0][i]=='.'){
                a[0][i]=1;
            }
            if(s[i][0]=='.'){
                a[i][0]=1;
            }
        }
        int h=0;
        for(int i=1;i<n;i++){
            for(int j=1;j<n;j++){
                if(s[i][j]=='.'){
                    a[i][j]=min({a[i-1][j-1],a[i][j-1],a[i-1][j]});
                    a[i][j]++;
                    h=max(h,a[i][j]);
                }
            }
        }
        cout<<h<<"\n";
    }
}
accuracy: 1
time_ms: 50
memory_kb: 9144
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while(true) {
        int n;
        cin >> n;
        if(n == 0) return 0;
        vector<string>s(n);
        for(int i = 0; i < n; i++) {
            cin >> s[i];
        }
        vector<vector<int>>sum(n+1,vector<int>(n+1));
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                sum[i+1][j+1] = (s[i][j] == '*');
            }
        }
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j < n; j++) {
                sum[i][j+1] += sum[i][j];
            }
        }
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j < n; j++) {
                sum[j+1][i] += sum[j][i];
            }
        }
        int l = 0,r = n+1;
        while(l+1 < r) {
            int mid = (l+r)/2;
            bool f = false;
            for(int i = 0; i+mid <= n; i++) {
                for(int j = 0; j+mid <= n; j++) {
                    int tmp = sum[i+mid][j+mid]+sum[i][j]-sum[i][j+mid]-sum[i+mid][j];
                    if(tmp == 0) {
                        f = true;
                        break;
                    }
                }
                if(f) break;
            }
            if(f) {
                l = mid;
            }
            else {
                r = mid;
            }
        }
        cout << l << "\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 8040
final_rank: 3

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

#define N 1001

using namespace std;

int n;
// 0:hol, 1:ver
int memo[N][N][2];
int diagonal[N][N];

int dp[N][N];

int main() {
    while(cin >> n, n != 0){

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                char c;
                cin >> c;

                if(c == '.') {
                    memo[i][j][0] =  j > 0 ? memo[i][j - 1][0] + 1 : 1;
                    memo[i][j][1] = i > 0 ? memo[i - 1][j][1] + 1 : 1;
                } else {
                    memo[i][j][0] = 0;
                    memo[i][j][1] = 0;
                }

                diagonal[i][j] = min(memo[i][j][0], memo[i][j][1]);

                dp[i][j] = 0;
            }
        }

        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(i > 0 && j > 0) {
                    dp[i][j] = min(dp[i - 1][j - 1] + 1, diagonal[i][j]);
                } else {
                    dp[i][j] = diagonal[i][j];
                }
                ans = max(dp[i][j], ans);
            }
        }

        cout << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 18728
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<string> A(n);
        for(auto &&s:A)cin >> s;
        vector<vector<int>> dp(n, vector<int>(n));
        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(A[i][j] == '*')continue;
                if(i == 0 || j == 0)dp[i][j] = 1;
                else dp[i][j] = min(dp[i - 1][j - 1], min(dp[i][j - 1], dp[i - 1][j])) + 1;
                ans = max(ans, dp[i][j]);
            }
        }
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 50
memory_kb: 9152
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        vector<string> s(n);
        vector<vector<int>> dp(n,vector<int>(n));
        int res = 0;
        for(int i=0;i<n;i++){
            cin >> s[i];
            for(int j=0;j<n;j++){
                if(s[i][j] == '.')dp[i][j] = 1, res = 1;
            }
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<n;j++){
                if(s[i][j] == '.'){
                    dp[i][j] = min({dp[i-1][j-1], dp[i-1][j], dp[i][j-1]}) + 1;
                    res = max(res, dp[i][j]);
                }
            }
        }
        cout << res << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 8308
final_rank: 4

code_snippet: #include <stdio.h>
#include <string.h>
#include <stdlib.h>



char g_data[1001][1001];
int  g_dp[1001][1001];
#define self_min(x,y) (x) > (y) ? (y):(x)

void slove(int n)
{
	int v1;
	int mv = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (g_data[i - 1][j - 1] == '*')
			{
				g_dp[i][j] = 0;
			}
			else
			{
				v1 = self_min(g_dp[i - 1][j - 1], g_dp[i][j - 1]);
				v1 = self_min(v1, g_dp[i - 1][j]);
				g_dp[i][j] = v1 + 1;
				if (mv < g_dp[i][j])
					mv = g_dp[i][j];
			}
		}
	}
	printf("%d\n", mv);
}

int main()
{
	int n;
	while (1)
	{
		scanf("%d", &n);
		if (n == 0)
			break;
		memset(g_data, 0, sizeof(g_data));
		memset(g_dp, 0, sizeof(g_dp));
		for (int i = 0; i < n; i++)
		{
			scanf("%s", g_data[i]);
		}
		slove(n);
	}
}
accuracy: 1
time_ms: 10
memory_kb: 7624
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
#include<sstream>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int Mod=998244353;
const int inf=mod*mod;
const double eps=1e-9;
int dp[1000][1000];
signed main(){
	int n;
	while(cin>>n,n){
		string str[1000];
		for(int i=0;i<n;i++)
			cin>>str[i];
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(str[i][j]=='*'){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=min(i,j);
				if(i!=0)
					dp[i][j]=min(dp[i][j],dp[i-1][j]);
				if(j!=0)
					dp[i][j]=min(dp[i][j],dp[i][j-1]);
				if(i!=0&&j!=0)
					dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
				dp[i][j]++;
				ans=max(ans,dp[i][j]);
			}
		}
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 50
memory_kb: 13104
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n,dp[1010][1010],ans;
string s[1010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(cin >> n, n){
        rep(i,n) cin >> s[i];
        ans = 0;
        rep(i,n)rep(j,n) dp[i][j] = 0;
        rep(i,n)rep(j,n){
            if(s[i][j] == '*') continue;
            dp[i + 1][j + 1] = min({dp[i][j], dp[i][j + 1], dp[i + 1][j]}) + 1;
            ans = max(ans, dp[i + 1][j + 1]);
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 8032
final_rank: 2

code_snippet: #include<bits/stdc++.h>

using namespace std;
using ll = long long;
inline int ri() { int n; cin >> n; return n;}
void solve();

int main()
{
	while(true)solve();
}

void solve()
{
	int n; cin >> n;
	if(!n) exit(0);

	vector<string> g(n);
	vector dp(n + 1, vector(n + 1, 0));
	for(int i = 0; i < n; i++)cin >> g[i];

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {

			if(g[i][j] == '*')continue;
			dp[i + 1][j + 1] = min({dp[i + 1][j], dp[i][j + 1], dp[i][j]}) + 1;

		}
	}

	int nax = 0;
	for(auto &i: dp)for(auto j: i)nax= max(nax, j);
	cout << nax << endl;

}
accuracy: 1
time_ms: 50
memory_kb: 9172
final_rank: 8

code_snippet: #include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1e18
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)

int main(){
	
	int n;
	while(true){
		cin>>n;
		if(n==0)break;
		vector<string> S(n);
		rep(i,n)cin>>S[i];
		
		vector dp(n,vector<int>(n,0));
		
		rep(i,n){
			rep(j,n){
				if(S[i][j]=='*')continue;
				dp[i][j] = 1;
				if(i==0||j==0)continue;
				dp[i][j] = max(dp[i][j],1+min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]}));
			}
		}
		
		int ans = 0;
		rep(i,n){
			rep(j,n)ans = max(ans,dp[i][j]);
		}
		
		cout<<ans<<endl;
		
	}
	
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 9248
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		string s[n];
		for(int i=0;i<n;i++) cin>>s[i];
		int a[n+1][n+1]={};
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++){
				if(s[i-1][j-1]=='.') a[i][j]=min(a[i-1][j-1],min(a[i-1][j],a[i][j-1]))+1;
				else a[i][j]=0;
			}
		int p=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				p=max(p,a[i+1][j+1]);
		cout<<p<<endl;
	}
}
accuracy: 1
time_ms: 90
memory_kb: 8060
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        
        vector<vector<char>> g(n, vector<char>(n));
        vector<vector<int>> dp(n, vector<int>(n));
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                cin >> g[i][j];
                if(g[i][j] == '*') dp[i][j] = 0;
                else dp[i][j] = 1;
            }
        }
        int ans = 0;
        for(int i=1; i<n; i++){
            for(int j=1; j<n; j++){
                if(g[i][j] == '*') continue;
                dp[i][j] = min({dp[i-1][j-1], dp[i-1][j], dp[i][j-1]}) +1;
                ans = max(ans, dp[i][j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 7828
final_rank: 16

code_snippet: #include <iostream>

int min3(int x, int y, int z)
{
	if (x>y) return y>z ? z : y;
	else return x>z ? z : x;
}

int main()
{
	while (true) {
		int size;
		std::cin >> size;
		
		if (size==0) break;
		
		std::string* board = new std::string[size];
		for (int i=0; i<size; i++) {
			std::cin >> board[i];
		}
		
		int** max_square_size = new int*[size]; 
		for (int i=0; i<size; i++) {
			max_square_size[i] = new int[size];
		}
		
		int max_size = 0;
		for (int i=size-1; i>=0; i--) {
			for (int j=size-1; j>=0; j--) {
				if (board[i][j] == '*') max_square_size[i][j] = 0;
				else if (i==size-1 || j==size-1) max_square_size[i][j] = 1;
				else if (board[i+1][j] == '*' || board[i][j+1] == '*' || board[i+1][j+1] == '*') max_square_size[i][j] = 1;
				else {
					max_square_size[i][j] = min3(max_square_size[i+1][j], 
						max_square_size[i][j+1], max_square_size[i+1][j+1]) + 1;
				}
				if (max_square_size[i][j] > max_size) {
					max_size = max_square_size[i][j];
				}
			}
		}
		
		for (int i=0; i<size; i++) delete[] max_square_size[i];
		delete[] max_square_size;
		delete[] board;
		
		std::cout << max_size << std::endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 7968
final_rank: 13

code_snippet: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n) {
        vector<vector<int>> v(n, vector<int>(n));
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            for (int j = 0; j < n; ++j) {
                v[i][j] = (s[j] == '.' ? min(i+1, j+1) : 0);
                if(!v[i][j]) continue;
                if(i) v[i][j] = min(v[i][j], v[i-1][j]+1);
                if(j) v[i][j] = min(v[i][j], v[i][j-1]+1);
                if(i && j) v[i][j] = min(v[i][j], v[i-1][j-1]+1);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                ans = max(ans, v[i][j]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 6700
final_rank: 10

code_snippet: #include <iostream>

using namespace std;

int n;
string s;
int dp[1000][1000];

int main() {

    while (cin >> n) {
        if (n == 0) break;

        for (int i = 0; i < n; i++) {
            cin >> s;
            for (int j = 0; j < n; j++) {
                dp[i][j] = s[j] == '.' ? 1 : 0;
            }
        }

        int ans = 0;

        for (int i = 1; i < n; i++) {
            for (int j = 1; j < n; j++) {
                if (dp[i][j]) {
                    dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
                    ans = max(ans, dp[i][j]);
                }
            }
        }

        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 90
memory_kb: 7000
final_rank: 11

code_snippet: #include <iostream>

using namespace std;

int main() {
    int n;
    string s;

    while (cin >> n) {
        if (n == 0) break;

        int dp[n][n];

        for (int i = 0; i < n; i++) {
            cin >> s;
            for (int j = 0; j < n; j++) {
                dp[i][j] = s[j] == '.' ? 1 : 0;
            }
        }

        int ans = 0;

        for (int i = 1; i < n; i++) {
            for (int j = 1; j < n; j++) {
                if (dp[i][j]) {
                    dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
                    ans = max(ans, dp[i][j]);
                }
            }
        }

        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 90
memory_kb: 7124
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int squareSearching(int** table,int W,int H);

struct rect{
  int w;
  int h;
  bool operator<(const rect &another) const{
    return w*10000+h<another.w*10000+another.h;//w,h<1000
  };
  bool operator==(const rect &another) const{
    return w==another.w and h==another.h;
  };
};


int main(void){
  int n;
  char s[1020];
  while(1){
    cin>>n;
    if(n==0)break;
    int** table;
    table=(int **)malloc(sizeof(int*)*(n+2));
    for(int i=0;i<n+2;i++){
      table[i]=(int*)malloc(sizeof(int)*(n+2));
    }
    for(int i=0;i<n+2;i++){
      table[i][0]=0;
      table[i][n+1]=0;
    }
    for(int j=0;j<n+2;j++){
      table[0][j]=0;
      table[n-1][j]=0;
    }

    for(int i=0;i<n;i++){
      scanf("%s",s);
      for(int j=0;j<n;j++){
        if(s[j]=='*'){
          table[i+1][j+1]=0;
        }
        else{
          table[i+1][j+1]=1;
        }
      }
    }
    cout<<squareSearching(table,n,n)<<endl;

  }
  return 0;
}

int squareSearching(int** table,int W,int H){
  vector<rect> dp[H][W];
  int retval=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(table[i+1][j+1]==0){
        continue;
      }

      if(table[i+1][j]==0 and table[i][j+1]==0){
        rect r;
        r.h=1;
        r.w=1;
        dp[i][j].push_back(r);
      }
      else if(table[i+1][j]==0 and table[i][j+1]==1){
        int height=0;
        vector<rect> v;
        v=dp[i-1][j];
        rect tmp;
        for(int k=0;k<v.size();k++){
          tmp=v[k];
          height=max(height,tmp.h);
        }
        if(v.empty()==false){
          height++;
        }
        rect r;
        r.h=height;
        r.w=1;
        dp[i][j].push_back(r);
      }
      else if(table[i+1][j]==1 and table[i][j+1]==0){
        int width=0;
        vector<rect> v;
        v=dp[i][j-1];
        rect tmp;
        for(int k=0;k<v.size();k++){
          tmp=v[k];
          width=max(width,tmp.w);
        }
        if(v.empty()==false){
          width++;
        }


        rect r;
        r.h=1;
        r.w=width;
        dp[i][j].push_back(r);
      }
      else{
        int width=0;
        vector<rect> v;
        rect tmp2;
        v=dp[i][j-1];
        for(int k=0;k<v.size();k++){
          tmp2=v[k];
          width=max(width,tmp2.w);
        }
        if(v.empty()==false){
          width++;
        }

        int height=0;
        v=dp[i-1][j];
        for(int k=0;k<v.size();k++){
          tmp2=v[k];
          height=max(height,tmp2.h);
        }
        if(v.empty()==false){
          height++;
        }

        vector<rect> tmp;
        for(int k=0;k<dp[i][j-1].size();k++){
          rect r;
          int h=min(dp[i][j-1][k].h,height);
          int w=dp[i][j-1][k].w+1;
          r.h=h;
          r.w=w;
          tmp.push_back(r);
        }
        for(int k=0;k<dp[i-1][j].size();k++){
          rect r;
          int h=dp[i-1][j][k].h+1;
          int w=min(dp[i-1][j][k].w,width);
          r.h=h;
          r.w=w;
          tmp.push_back(r);
        }
        sort(tmp.begin(),tmp.end());
        tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());

        dp[i][j]=tmp;
      }
      vector<rect> v=dp[i][j];
      for(int k=0;k<v.size();k++){
        retval=max(min((int)v[k].h,(int)v[k].w),retval);
      }

    }
  }

  return retval;
}
accuracy: 1
time_ms: 820
memory_kb: 83332
final_rank: 20