Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using LINT = long long int;
- using PII = pair<int,int>;
- #define PB push_back
- #define FI first
- #define SE second
- #define REP(i,n) for(int i=0;i<(n);++i)
- #define FOR(i, a, b) for(int i=(a);i<(b);++i)
- int t;
- int n;
- string grid[2007];
- int dpu[2007][2007];
- int dpb[2007][2007];
- int dpl[2007][2007];
- int dpr[2007][2007];
- void process(){
- cin>>n;
- REP(i,n)cin>>grid[i];
- memset(dpu, 0, sizeof(dpu));
- memset(dpb, 0, sizeof(dpb));
- memset(dpl, 0, sizeof(dpl));
- memset(dpr, 0, sizeof(dpr));
- FOR(i,1,n)
- REP(j,n){
- if(grid[i][j]=='#'){
- dpu[i][j] = dpu[i-1][j] + (grid[i-1][j]=='#');
- }
- }
- REP(j,n)
- FOR(i,1,n){
- if(grid[j][i]=='#'){
- dpl[j][i] = dpl[j][i-1] + (grid[j][i-1]=='#');
- }
- }
- for(int i = n-2;i>=0;--i)
- REP(j,n){
- if(grid[i][j]=='#'){
- dpb[i][j] = dpb[i+1][j] + (grid[i+1][j]=='#');
- }
- }
- REP(j,n)
- for(int i = n-2;i>=0;--i){
- if(grid[j][i]=='#'){
- dpr[j][i] = dpr[j][i+1] + (grid[j][i+1]=='#');
- }
- }
- int best = 0;
- REP(i,n)
- REP(j,n)
- if(grid[i][j]=='#') {
- best = max(best, min(dpr[i][j],min(dpl[i][j],min(dpu[i][j],dpb[i][j])))+1);
- // cout<<i<<' '<<j<<' '<<best<<endl;
- }
- cout<<best<<endl;
- }
- int main() {
- cin>>t;
- while(t--)process();
- return 0;
- }
Add Comment
Please, Sign In to add comment