20分求调

B4005 [GESP202406 四级] 黑白方块

ywtank @ 2024-11-30 07:43:15

#include <bits/stdc++.h>
using namespace std;
int a[20][20],f[20][20];
int mi=INT_MIN;
int main(){
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            char c;
            cin >> c;
            if(c=='\n')cin >> c;
            if(c=='0')a[i][j]=1;
            else a[i][j]=-1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            f[i][j]=f[i][j-1]+f[i-1][j]-f[i-1][j-1]+a[i][j];
        }
    }
    for(int x1=1;x1<=n;x1++){
        for(int y1=1;y1<=m;y1++){
            for(int x2=x1;x2<=n;x2++){
                for(int y2=y1;y2<=m;y2++){
                    if(x2==x1 && y2==y1)continue;
                    int ma=f[x2][y2]-f[x2][y1]-f[x1][y2]+f[x1][y1];
                    if(ma==0){
                        mi=max((x2-x1)*(y2-y1),mi);
                    }
                }
            }
        }
    }
    if(mi==INT_MIN)cout << 0;
    else cout << mi;
    return 0;
}

希望各位大佬帮忙看看


|