Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Alif_Sama

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

Language: cpp

Time: 0.009 second

Submitted On: 2025-10-09 07:06:01

#include <iostream>
using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    int arr[n][m] = {0};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> arr[i][j];
        }
    }
    //just print array debug test heh
    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < m; j++) {
    //         cout << arr[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    int s;
    cin >> s;
    int minus = 0,plus = 0,even = 0,odd = 0;
    bool Bminus = false,Bplus = false,Beven = false,Bodd = false;
    for (int i = 0; i < s; i++) {
        int a,b;
        cin >> a >> b;
        if (a-1 >= 0 && a-1 <= n-1 && b-1 >= 0 && b-1 <= m-1) {
            Bminus = false,Bplus = false,Beven = false,Bodd = false;
            int num = arr[a-1][b-1];
            if (num == 0) {
                even++;
                Beven = true;
                continue;
            } else if (num > 0 && num % 2 == 0) {
                plus++;
                even++;
                Bplus = true;
                Beven = true;
            } else if (num > 0 && num % 2 == 1) {
                plus++;
                odd++;
                Bplus = true;
                Bodd = true;
            } else if (num < 0 && abs(num) % 2 == 0) {
                minus++;
                even++;
                Bminus = true;
                Beven = true;
            } else if (num < 0 && abs(num) % 2 == 1) {
                minus++;
                odd++;
                Bminus = true;
                Bodd = true;
            }
        } else {
            if (Bplus) {
                plus++;
            }
            if (Bminus) {
                minus++;
            }
            if (Beven) {
                even++;
            }
            if (Bodd) {
                odd++;
            }
        }
    }
    printf("%d %d %d %d", plus,minus,even,odd);
}