#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
for (int test = 1; test <= T; ++test) {
int N, M;
cin >> N >> M;
vector<string> line(N);
for (int i = 0; i < N; ++i)
cin >> line[i];
int ans = 0, fx=-1,fy=-1,lx=-1,ly=-1, oneCount=0;
for(int i = 0;i < N;i++)
{
for(int j = 0;j < M;j++)
{
if(line[i].at(j) == '1')
{
if(fx==-1){
fx = i;
fy = j;
}
oneCount++;
}
}
}
for(int i = N-1;i >= 0;i--)
{
for(int j = M-1;j >= 0;j--)
{
if(lx==-1 && line[i].at(j) == '1')
{
lx = i;
ly = j;
}
}
}
//cout << fx << " " << fy << endl << lx << " " << ly << endl;
//cout << oneCount << endl << fx << " " << fy << endl << lx << " " << ly << endl;
if(fx > lx || fy > ly || fx == -1 || lx == -1)
{
ans = 0;
}
else
{
//cout << "aaaaaaaaaa";
int counter=0;
bool plsbreak = false;
for(int i = fx;i <= lx;i++)
{
for(int j = fy;j <= ly;j++)
{
if(line[i].at(j) == '1')
{
counter++;
}
else
{
plsbreak = true;
break;
}
}
if(plsbreak)
{
break;
}
}
//cout << counter;
if(counter != oneCount || plsbreak)
{
ans = 0;
}
else
{
ans = 1;
}
}
cout << ans << endl;
}
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 1ms | 508 KiB | ||||
2 | Elfogadva | 1ms | 320 KiB | ||||
subtask2 | 50/50 | ||||||
3 | Elfogadva | 4ms | 424 KiB | ||||
4 | Elfogadva | 4ms | 320 KiB | ||||
5 | Elfogadva | 7ms | 568 KiB | ||||
6 | Elfogadva | 7ms | 724 KiB | ||||
7 | Elfogadva | 2ms | 320 KiB | ||||
subtask3 | 50/50 | ||||||
8 | Elfogadva | 4ms | 320 KiB | ||||
9 | Elfogadva | 7ms | 320 KiB | ||||
10 | Elfogadva | 26ms | 1052 KiB | ||||
11 | Elfogadva | 54ms | 2248 KiB | ||||
12 | Elfogadva | 61ms | 2620 KiB | ||||
13 | Elfogadva | 32ms | 1848 KiB | ||||
14 | Elfogadva | 46ms | 2356 KiB | ||||
15 | Elfogadva | 75ms | 4124 KiB | ||||
16 | Elfogadva | 45ms | 2752 KiB | ||||
17 | Elfogadva | 2ms | 320 KiB |