对于每个位置找,延伸上下左右连续1,然后拿里面最小的。
考虑最坏情况500*500*500*2=25*1e7。(时间复杂度有点高...
1 #include <set> 2 #include <map> 3 #include <queue> 4 #include <deque> 5 #include <stack> 6 #include <cmath> 7 #include <cstdio> 8 #include <vector> 9 #include <string> 10 #include <cstring> 11 #include <fstream> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 16 #define eps 1e-8 17 #define pb push_back 18 #define PI acos(-1.0) 19 #define INF 0x3f3f3f3f 20 #define clr(a,b) memset(a,b,sizeof(a) 21 #define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 22 23 const int N=600; 24 typedef long long ll; 25 typedef unsigned long long ull; 26 char s[N][N]; 27 28 int main(){ 29 int n,ans=0; 30 scanf("%d",&n); 31 for(int i=1;i<=n;i++){ 32 scanf("%s",s[i]+1); 33 } 34 for(int i=2;i<n;i++){ 35 for(int j=2;j<n;j++){ 36 if(s[i][j]=='1'){ 37 int l=0,r=0,u=0,d=0; 38 for(int k=j+1;k<=n;k++) if(s[i][k]=='1') r++;else break; 39 for(int k=j-1;k>=1;k--) if(s[i][k]=='1') l++;else break; 40 for(int k=i+1;k<=n;k++) if(s[k][j]=='1') d++;else break; 41 for(int k=i-1;k>=1;k--) if(s[k][j]=='1') u++;else break; 42 l=min(l,r); 43 u=min(u,d); 44 ans=max(ans,min(l,u)); 45 } 46 } 47 } 48 printf("%d\n",ans); 49 return 0; 50 }