#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 5*1e5+5, INF = 4e18+9;
void solve(){
ll W, L, k;
cin >> W >> L >> k;
if((W*L - k)%3 != 0){
cout << "NO";
return;
}
if(k == 0){
if(W > 1 && L > 1 && W*L%6 == 0){
cout << "YES";
}else{
cout << "NO";
}
return;
}
struct point{
ll x, y;
};
vector<point> a(k+1);
for(int i = 1; i <= k; i++){
cin >> a[i].x >> a[i].y;
}
if(W > L){
swap(W, L);
for(int i = 1; i <= k; i++){
swap(a[i].x, a[i].y);
}
}
a.push_back({0, INF});
a.push_back({0, INF});
if(W == 2){
ll cur = 0;
sort(a.begin()+1, a.end(), [&](point a, point b){return a.y < b.y;});
int i = 1;
while(i <= k){
if(a[i].y == a[i+1].y){
if((a[i].y-cur-1)%3 == 0){
cur = a[i].y;
i++;
}else{
cout << "NO";
return;
}
}else{
if(cur >= a[i].y){
cout << "NO";
return;
}
if((a[i].y-1-cur-1)%3 == 0){
cur = a[i].y;
}else if((a[i].y-cur-1)%3 == 0){
cur = a[i].y+1;
}else{
cout << "NO";
return;
}
}
i++;
}
cout << "YES";
return;
}
cout << "YES";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("TRIOMINO.inp", "r", stdin);
//freopen("TRIOMINO.out", "w", stdout);
int t;
cin >> t;
while(t--){
solve();
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |