建议加强数据
查看原帖
建议加强数据
565707
mediocre_楼主2023/7/17 15:56

O(n⁵)都能过。。。

#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1005][1005];
int main(){
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= n;++i)
	    for (int j = 1;j <= m;++j)
		    scanf("%d",&a[i][j]);
	int ans = 0;
    for (int i = 1;i <= n;++i){
        for (int j = 1;j <= m;++j){
			int xy = 0;
			while (1){
			    xy++;
			    bool use = false;
			    for (int sx = i;sx <= xy + i - 1;++sx){
			        for (int sy = j;sy <= xy + j - 1;++sy){
			        	if (sx > n || sy > m){
							use = true;
					        break;
			        	}
					    if (a[sx][sy] != 1){
					        use = true;
					        break;
					    }
				        
				    }
			    }
				if (!use && xy > ans)ans = xy;
				if (use)break;
			}
		}
    }
	printf("%d",ans); 
	return 0;
}
2023/7/17 15:56
加载中...