Submission

Status:

PPPPPP-PPP

Subtask/Task Score:

90/100

Score: 90

User: mik

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

Language: cpp

Time: 0.006 second

Submitted On: 2026-10-11 09:53:37

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int r, c;
    cin >> r >> c;
    vector<vector<int>> ar(r, vector<int>(c));
    for (int i = 0; i < r; i++){
        for (int j = 0; j < c; j++){
            cin >> ar[i][j];
        }
    }
    
    int n, x, y;
    long long p = 0, l = 0, e = 0, o = 0; // ใช้ long long ป้องกันกรณี n มีค่าสูงมาก
    int q = 0; // กำหนดค่าเริ่มต้นให้ q ป้องกันค่าขยะ (Garbage Value)
    
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> x >> y;
        
        // ถ้าพิกัดอยู่ในตาราง ให้อัปเดตค่า q
        // หากพิกัดหลุดออกนอกตาราง q จะคงค่าจากรอบก่อนหน้าอัตโนมัติ[cite: 1]
        if (x >= 1 && x <= r && y >= 1 && y <= c) {
            q = ar[x - 1][y - 1];
        }
        
        // ตรวจสอบเงื่อนไขตามค่า q ปัจจุบัน
        if (q > 0) p++;
        if (q < 0) l++;
        if (q % 2 == 0) e++;
        else o++;
    }
    
    cout << p << ' ' << l << ' ' << e << ' ' << o << "\n";
    return 0;
}