hack & 请求加强数据
查看原帖
hack & 请求加强数据
476985
Accelessar楼主2023/7/16 21:50

hack 我自己的代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1510;
int n,m,a[N],c,h[N],l[N],r[N],ans;

int main(){
    cin.tie(0)->sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)cin>>c,c^a[j]?(h[j]++,a[j]=c):h[j]=1;
        for(int j=1;j<=m;j++)l[j]=r[j]=j;
        for(int j=1;j<=m;j++)while(l[j]>1&&h[j]<=h[l[j]-1])l[j]=l[--l[j]];
        for(int j=m;j;j--)while(r[j]<m&&h[j]<=h[r[j]+1])r[j]=r[++r[j]];
        for(int j=1;j<=m;j++)ans=max(ans,min(h[j],r[j]-l[j]+1));
    }return cout<<ans,0;
}

AC 记录

显然,这份代码只考虑了纵向相邻的格子颜色不能相同,并没有考虑横向的。

我自己拍出了一组数据:

输入

6 8
1 0 1 0 0 0 1 0
0 1 0 1 0 1 0 1
0 1 1 1 0 0 0 0
0 0 1 0 0 0 1 0
1 0 0 1 1 0 0 1
1 0 1 0 0 0 0 0

错误输出:

3

正确输出:

2
2023/7/16 21:50
加载中...