112202024-07-17 14:20:48bzyOil Fieldcpp14Wrong answer 0/10087ms1224 KiB
#include <bits/stdc++.h>
using namespace std;
void run_case()
{
    int n,m;
    cin>>n>>m;
    vector <string> matrix;
    bool valid = true;
    bool firstrow = false;
    bool hadone = false;
    for(int i = 0; i< n ;i++){
        string s;
        cin>>s;
        matrix.push_back(s);
        bool f1 = false;
        if(valid == true){
            if(firstrow == false){
                for(int j = 0;j<m;j++){
                    if(s[j] == '1' && f1 == false){
                        f1 = true;
                        firstrow = true;
                        hadone = true;
                    }
                    else if(s[j] == '1' && f1 == true){
                        if(s[j-1] != '1') valid = false;

                    }
                }
            }
            else{
                for(int j = 0;j<m;j++){
                    if(s[j] == '1' && f1 == false){
                        f1 = true;
                        if(matrix[i-1][j] != '1') valid = false;
                    }
                    else if(s[j] == '1' && f1 == true){
                        if(s[j-1] != '1' || matrix[i-1][j] != '1') valid = false;
                    }
                }
            }
        }
    }
    int occurance = 0;
    bool firstocc = false;
    for(int i = 1; i<n;i++){
        int freq = 0;
        if(firstocc == false){
            for(int j = 0;j<m;j++){
                if(matrix[i][j] == '1'){
                    firstocc = true;
                    freq++;
                }
            }
            occurance = freq;
        }
        else{
            for(int j = 0;j<m;j++){
                if(matrix[i][j] == '1') freq ++;
            }
            if(freq != 0 && freq != occurance) valid = false;
        }
    }
    if(valid == false || hadone == false) cout<<0<<endl;
    else cout<<1<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t-->0){
        run_case();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms356 KiB
2Accepted2ms356 KiB
subtask20/50
3Accepted8ms372 KiB
4Wrong answer8ms320 KiB
5Accepted12ms356 KiB
6Wrong answer12ms408 KiB
7Wrong answer4ms356 KiB
subtask30/50
8Wrong answer8ms492 KiB
9Wrong answer10ms384 KiB
10Accepted32ms356 KiB
11Accepted61ms492 KiB
12Accepted68ms484 KiB
13Accepted37ms616 KiB
14Accepted50ms720 KiB
15Accepted87ms1040 KiB
16Accepted54ms1224 KiB
17Wrong answer4ms376 KiB