105102024-04-03 20:38:09111Oil Fieldcpp17Accepted 100/10014ms18200 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--){
		int N,M;
		cin>>N>>M;
		vector<string>v(N);
		for(int i=0;i<N;i++){
			cin>>v[i];
		}
		int c=0,li=INT_MAX,hi=INT_MIN,lj=INT_MAX,hj=INT_MIN;
		for(int i=0;i<N;i++){
			for(int j=0;j<M;j++){
				if(v[i][j]=='1'){
					c++;
					li=min(li,i);
					hi=max(hi,i);
					lj=min(lj,j);
					hj=max(hj,j);
				}
			}
		}
		cout<<(c==(hi-li+1)*(hj-lj+1))<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2008 KiB
2Accepted3ms2040 KiB
subtask250/50
3Accepted3ms2252 KiB
4Accepted4ms2552 KiB
5Accepted4ms2704 KiB
6Accepted4ms2828 KiB
7Accepted3ms2816 KiB
subtask350/50
8Accepted3ms2832 KiB
9Accepted4ms3132 KiB
10Accepted9ms3872 KiB
11Accepted14ms6172 KiB
12Accepted14ms8816 KiB
13Accepted8ms10468 KiB
14Accepted12ms12496 KiB
15Accepted12ms16276 KiB
16Accepted8ms18200 KiB
17Accepted3ms16688 KiB