#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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2008 KiB | ||||
2 | Accepted | 3ms | 2040 KiB | ||||
subtask2 | 50/50 | ||||||
3 | Accepted | 3ms | 2252 KiB | ||||
4 | Accepted | 4ms | 2552 KiB | ||||
5 | Accepted | 4ms | 2704 KiB | ||||
6 | Accepted | 4ms | 2828 KiB | ||||
7 | Accepted | 3ms | 2816 KiB | ||||
subtask3 | 50/50 | ||||||
8 | Accepted | 3ms | 2832 KiB | ||||
9 | Accepted | 4ms | 3132 KiB | ||||
10 | Accepted | 9ms | 3872 KiB | ||||
11 | Accepted | 14ms | 6172 KiB | ||||
12 | Accepted | 14ms | 8816 KiB | ||||
13 | Accepted | 8ms | 10468 KiB | ||||
14 | Accepted | 12ms | 12496 KiB | ||||
15 | Accepted | 12ms | 16276 KiB | ||||
16 | Accepted | 8ms | 18200 KiB | ||||
17 | Accepted | 3ms | 16688 KiB |