Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: cyblox_boi

Problemset: สำรวจอาเรย์ 2

Language: cpp

Time: 0.005 second

Submitted On: 2025-10-17 09:24:42

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int r, c;
    cin >> r >> c;

    vector<int> countNumberTypes(4, 0);
    vector<bool> hasAdd(4, false);
    vector<vector<int>> numbers(r, vector<int>(c));

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            cin >> numbers[i][j];
        }
    }

    int k;
    cin >> k;

    for (int i = 0; i < k; i++)
    {
        int a, b;
        cin >> a >> b;

        a--;
        b--;

        if (a < 0 || a >= r || b < 0 || b >= c)
        {
            for (int i = 0; i < hasAdd.size(); i++)
            {
                if (hasAdd[i])
                {
                    countNumberTypes[i]++;
                }
            }

            continue;
        }

        int result = numbers[a][b];

        for (int i = 0; i < hasAdd.size(); i++)
        {
            if (hasAdd[i])
            {
                hasAdd[i] = false;
            }
        }

        if (result > 0)
        {
            countNumberTypes[0]++;
            hasAdd[0] = true;
        }
        else if (result < 0)
        {
            countNumberTypes[1]++;
            hasAdd[1] = true;
        }

        if (result % 2 == 0)
        {
            countNumberTypes[2]++;
            hasAdd[2] = true;
        }
        else
        {
            countNumberTypes[3]++;
            hasAdd[3] = true;
        }
    }

    for (const int &i : countNumberTypes)
    {
        cout << i << ' ';
    }

    cout << '\n';

    return 0;
}