Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Karatat007

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

Language: cpp

Time: 0.005 second

Submitted On: 2026-10-03 19:27:48

/*#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int r,c;
    int pos = 0,neg = 0,even = 0,odd = 0;
    cin >> r >> c;
    int cor[r][c];
    for(int i = 0;i < r;++i){
        for(int j = 0;j < c;++j){
            cin >> cor[i][j];
        }
    }
    int n;
    cin >> n;
    int remember;
    int z;
    for(int i = 0;i < n;++i){
        int x,y;
        cin >> x >> y;
        if(x >= 1 and y >= 1 and x <= r and y <= c){
            z = cor[x-1][y-1];
        }
        if(z % 2 == 0) ++even;
        else ++odd;
        if(z > 0) ++pos;
        else if(z < 0) ++neg;
    }
    cout << pos << ' ' << neg << ' ' << even << ' ' << odd; 
}

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long r, c;
    cin >> r >> c;
    vector<vector<long long>> cor(r, vector<long long>(c));
    for(long long i = 0; i < r; ++i)
        for(long long j = 0; j < c; ++j)
            cin >> cor[i][j];

    long long n;
    cin >> n;
    long long pos = 0, neg = 0, even = 0, odd = 0;
    long long z = 0;
    for(long long i = 0; i < n; ++i){
        long long x, y;
        cin >> x >> y;
        if(x >= 1 && y >= 1 && x <= r && y <= c){
            z = cor[x-1][y-1];
        }
        if(z % 2 == 0) ++even;
        else ++odd;
        if(z > 0) ++pos;
        else if(z < 0) ++neg;
    }
    cout << pos << ' ' << neg << ' ' << even << ' ' << odd;
}
    */
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long r, c;
    cin >> r >> c;
    // bit0 = คี่, bit1 = บวก, bit2 = ลบ
    vector<unsigned char> cell((size_t)(r * c), 0);

    string s;
    for(long long i = 0; i < r * c; ++i){
        cin >> s;
        size_t st = 0;
        bool negative = false;
        if(s[0] == '-'){ negative = true; st = 1; }
        else if(s[0] == '+'){ st = 1; }

        bool nonzero = false;
        for(size_t k = st; k < s.size(); ++k)
            if(s[k] != '0'){ nonzero = true; break; }

        unsigned char code = 0;
        if((s.back() - '0') % 2 == 1) code |= 1;
        if(nonzero) code |= negative ? 4 : 2;
        cell[i] = code;
    }

    long long n;
    cin >> n;
    long long pos = 0, neg = 0, even = 0, odd = 0;
    unsigned char z = 0;
    bool has = false;

    for(long long i = 0; i < n; ++i){
        long long x, y;
        cin >> x >> y;
        if(x >= 1 && y >= 1 && x <= r && y <= c){
            z = cell[(x - 1) * c + (y - 1)];
            has = true;
        }
        if(!has) continue;
        if(z & 1) ++odd; else ++even;
        if(z & 2) ++pos;
        if(z & 4) ++neg;
    }
    cout << pos << ' ' << neg << ' ' << even << ' ' << odd;
}