题目
分析
矩阵前缀和
代码
1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int map[1001][1001],sum[1001][1001]; 5 int ans; 6 int main () 7 { 8 int n; 9 char c; 10 cin>>n; 11 for (int i=1;i<=n;i++) 12 for (int j=1;j<=n;j++) 13 { 14 cin>>c; 15 map[i][j]=c-'0'; 16 } 17 for (int i=1;i<=n;i++) 18 for (int j=1;j<=n;j++) 19 sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+map[i][j]; 20 for (int i=1;i<=n;i++) 21 { 22 for (int j=1;j<=n;j++) 23 { 24 for (int k=sqrt(ans);i+k-1<=n&&j+k-1<=n;k++) 25 { 26 if (sum[i+k-1][j+k-1]-sum[i+k-1][j-1]-sum[i-1][j+k-1]+sum[i-1][j-1]==k*k) 27 ans=max(k*k,ans); 28 else break; 29 } 30 } 31 } 32 cout<<ans; 33 }