Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: NovemNotes
Problemset: สำรวจอาเรย์ 2
Language: cpp
Time: 0.005 second
Submitted On: 2025-10-15 13:51:22
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;cin >> n >> m;
vector<vector<int>> v(n+1,vector<int>(m+1,0));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> v[i][j];
}
}
int a,b,c,d;
a=b=c=d=0;
int q;cin >> q;
int last=0;
bool chk=false;
while(q--){
int x,y;cin >> x >> y;
if((x<1||x>n||y<1||y>m) && chk){
if(last>0){
a++;
}else if(last<0){
b++;
}
if(last%2==0){
c++;
}else if(last%2==1||last%2==-1){
d++;
}
continue;
}else if(x<1||x>n||y<1||y>m){
continue;
}
last=v[x][y];
chk=true;
if(v[x][y]>0){
a++;
}else if(v[x][y]<0){
b++;
}
if(v[x][y]%2==0){
c++;
}else if(v[x][y]%2==1 || v[x][y]%2==-1){
d++;
}
}
cout << a << " " << b << " " << c << " " << d << "\n";
return 0;
}