122422024-12-10 13:05:42AGergoOil Fieldcpp17Elfogadva 100/10075ms4124 KiB
#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ÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms508 KiB
2Elfogadva1ms320 KiB
subtask250/50
3Elfogadva4ms424 KiB
4Elfogadva4ms320 KiB
5Elfogadva7ms568 KiB
6Elfogadva7ms724 KiB
7Elfogadva2ms320 KiB
subtask350/50
8Elfogadva4ms320 KiB
9Elfogadva7ms320 KiB
10Elfogadva26ms1052 KiB
11Elfogadva54ms2248 KiB
12Elfogadva61ms2620 KiB
13Elfogadva32ms1848 KiB
14Elfogadva46ms2356 KiB
15Elfogadva75ms4124 KiB
16Elfogadva45ms2752 KiB
17Elfogadva2ms320 KiB