Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: TonnamSora

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

Language: cpp

Time: 0.010 second

Submitted On: 2025-10-07 22:45:12

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

int main(){
    int y, x;
    cin >> y >> x;
    int a[y][x];
    for(int i = 0; i < y; i++){
        for(int j = 0; j < x; j++){
            cin >> a[i][j];
        }
    }
    int N;
    cin >> N;
    int q[N], p[N];
    for(int i = 0; i < N; i++){
        cin >> q[i] >> p[i];
    }
    int pos = 0, neg = 0, even = 0, odd = 0;
    int po = 0, ne = 0, ev = 0, od = 0;
    int f;
    for(int i = 0; i < N; i++){
        p[i]--;
        q[i]--;
        if (p[i] < 0 || p[i] >= x || q[i] < 0 || q[i] >= y){
            if(ne == 1){
                neg++;
            }
            if(po == 1){
                pos++;
            }
            if(ev == 1){
                even++;
            }
            if(od == 1){
                odd++;
            }
            continue;
        }
        f = a[q[i]][p[i]];
        if(f < 0){
            neg++;
            ne = 1;
            po = 0;
        }
        if(f > 0){
            pos++;
            po = 1;
            ne = 0;
        }
        if(f == 0){
            po = 0;
            ne = 0;
        }
        if(abs(f) % 2 == 0){
            even++;
            ev = 1;
            od = 0;
        }
        if(abs(f) % 2 == 1){
            odd++;
            ev = 0;
            od = 1;
        }
    }
    cout << pos << " " << neg << " " << even << " " << odd;
}