Submission

Status:

PPPPPPPPPP

Score: 100

User: Pera

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

Language: cpp

Time: 0.006 second

Submitted On: 2025-05-18 17:22:05

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int rSize, cSize;
    cin >> rSize >> cSize;

    vector<vector<int>> grid(rSize, vector<int>(cSize));

    for (int i = 0; i < rSize; ++i) {
        for (int j = 0; j < cSize; ++j) {
            cin >> grid[i][j];
        }
    }

    int n; cin >> n;
    int posCount{0};
    int negCount{0};
    int evenCount{0};
    int oddCount{0};

    bool last_is_pos;
    bool last_is_zero;
    bool last_is_even;

    bool firsttime = false;

    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        if (x >= 1 && x <= rSize && y >= 1 && y <= cSize) {
            int value = grid[x-1][y-1];

            if (value > 0) {
                posCount++;
            } else if (value < 0) {
                negCount++;
            }

            if (value % 2 == 0) {
                evenCount++;
            } else {
                oddCount++;
            }

            last_is_pos = (value > 0);
            last_is_zero = (value == 0);
            last_is_even = (value % 2 == 0);

            firsttime = true;

        } else {
            if (firsttime) {
                if (last_is_pos) {
                    posCount++;
                } else if (!last_is_pos && !last_is_zero) {
                    negCount++;
                }

                if (last_is_even) {
                    evenCount++;
                } else {
                    oddCount++;
                }
            }
        }
    }

    cout << posCount << ' ' << negCount << ' ' << evenCount << ' ' << oddCount << '\n';

    return 0;
}