112182024-07-17 11:04:35zhuyiOil Fieldcpp14Wrong answer 0/10086ms4236 KiB
#include <bits/stdc++.h>
using namespace std;
void run_case()
{
    int n,m;
    cin>> n >> m;
    bool valid = true;
    bool hadone = false;
    vector <string> matrix;
    vector <vector <int>> oilfield;
    for(int i = 0;i<n;i++){
        string o;
        cin>>o;
        vector <int > v;
        matrix.push_back(o);
        for(int j = 0;j<m;j++){
            if(o[j] == '1'){
                hadone = true;
                v.push_back(j);
                if(v.size() > 1){
                    if(v[v.size()-1] - v[v.size()-2] > 1) valid = false;
                }
            }
        }
        v.push_back(i);
        oilfield.push_back(v);
        
    }
    /*
    cout<<endl;
    for(int i = 0;i<oilfield.size();i++){
        for(int j = 0;j<oilfield[i].size();j++){
            cout<<oilfield[i][j];
        }
        cout<<endl;

    }
    */
    for(int i = 1;i<oilfield.size();i++){
        if(oilfield[i][oilfield[i].size()-1] - oilfield[i-1][oilfield[i-1].size()-1] > 1){
            valid = false;
        }
        if(oilfield[i].size() - oilfield[i-1].size() != 0 && (oilfield[i].size() != 1 && oilfield[i-1].size() != 1)){
            valid = false;
            break;
        }
        if(oilfield[i].size() > 1 && oilfield[i-1].size() > 1){
            for(int j = 0; j < oilfield[i].size()-2;j++){
                if(oilfield[i][j] != oilfield[i-1][j]) valid = false;
            }
        }
        if(valid == false) break;

    }

    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
2Accepted3ms356 KiB
subtask20/50
3Wrong answer8ms356 KiB
4Wrong answer9ms356 KiB
5Wrong answer14ms632 KiB
6Wrong answer14ms632 KiB
7Wrong answer4ms408 KiB
subtask30/50
8Wrong answer8ms528 KiB
9Wrong answer13ms504 KiB
10Wrong answer37ms1084 KiB
11Wrong answer71ms2564 KiB
12Accepted74ms3072 KiB
13Accepted39ms2280 KiB
14Accepted57ms2908 KiB
15Accepted86ms4236 KiB
16Accepted54ms2940 KiB
17Wrong answer4ms356 KiB