Submission

Status:

PPPPPP-PPP

Subtask/Task Score:

90/100

Score: 90

User: Nuttykub

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

Language: cpp

Time: 0.005 second

Submitted On: 2026-10-02 10:30:16

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int m,n;
    cin>> m >> n;
    int matrix[m][n];
    for (int i = 0;i < m;i++){
        for (int j = 0;j<n;j++){
            cin >> matrix[i][j];
        }
    }
    int q;
    cin >> q;
    vector<int> gather;
    vector<int> ans(4,0);
    for (int i = 0;i < q;i++){
        int a,b;
        cin >> a>> b;
        if (a < 1 or b < 1 or a > m or b > n) {
            gather.push_back(123456789);
            continue;
        }
        gather.push_back(matrix[a-1][b-1]);
    }
    
    for (int i = 0;i < gather.size();i++){
        if (gather[i] == 123456789){
            if (gather[i-1] > 0){
                if (gather[i-1]%2 == 0) {
                    ans[2]++;
                    gather[i] = 2;
                }
                else {
                    ans[3]++;
                    gather[i] = 1;
                }
                ans[0]++;
            }
            else if (gather[i-1] < 0){
            if (abs(gather[i-1])%2 == 0) {
                ans[2]++;
                gather[i] = -2;
            }
            else {
                ans[3]++;
                gather[i] = -1;
            }
            ans[1]++;
        }
        else {
            ans[2]++;
            gather[i] = 0;
        }
        }
        else if (gather[i] > 0){
            if (gather[i]%2 == 0) ans[2]++;
            else ans[3]++;
            ans[0]++;
        }
        else if (gather[i] < 0){
            if (abs(gather[i])%2 == 0) ans[2]++;
            else ans[3]++;
            ans[1]++;
        }
        else  ans[2]++;
    }
    for (auto p : ans) cout << p << " ";
    
}