Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Kei

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

Language: cpp

Time: 0.005 second

Submitted On: 2026-10-08 14:36:19

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

void solve(){
    int r,c,k; cin >> r >> c;
    int p=0,n=0,e=0,o=0;
    bool even;
    char pn='A';
    vector<vector<int>> mat(r, vector<int>(c));
    for(vector<int>& row : mat){
        for(int& cn : row){
            cin >> cn;
        }
    }
    cin >> k;
    vector<pii> coords(k);
    for(int i=0;i<k;i++){
        cin >> coords[i].first >> coords[i].second;
    }
    for(pii& x : coords){
        if(x.first < 1 || x.first > r || x.second < 1 || x.second > c){
            if(pn=='A') continue;
            if(pn=='p')p++;
            else if(pn=='n') n++;
            if(even==true)e++;
            else o++;
            continue;
        }
        if(mat[x.first-1][x.second-1]%2 == 0){
            e++;
            even=true;
        }
        else{
            o++;
            even=false;
        }
        if(mat[x.first-1][x.second-1]>0){
            p++;
            pn='p';
        }
        else if(mat[x.first-1][x.second-1]<0){
            n++;
            pn='n';
        }
        else pn='0';
    }
    cout << p << ' ' << n << ' ' << e << ' ' << o;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}