#include <bits/stdc++.h>
#include <ratio>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define mp make_pair
#define pb push_back
#define INF (ll)1e18
ll MOD = (ll)(1e9+7);
void compute(ll i, ll w, ll cur, ll next, vector<ll> &wr){
if (i==w){
wr[next]=1;
}else{
if (i+1<w and !(cur&(1ull<<i)) and !(cur&(1ull<<(i+1))) and !(next&(1ull<<i))){
compute(i+2, w, ((cur|(1ull<<i))|(1ull<<(i+1))), next|(1ull<<i), wr);
}
if (i+1<w and !(cur&(1ull<<i)) and !(cur&(1ull<<(i+1))) and !(next&(1ull<<(i+1)))){
compute(i+2, w, ((cur|(1ull<<i))|(1ull<<(i+1))), next|(1ull<<(i+1)), wr);
}
if (i and !(cur&(1ull<<i)) and !(next&(1ull<<(i-1)) and !(next&(1ull<<i)))){
compute(i+1, w, ((cur|(1ull<<i))), (next|(1ull<<(i-1)|(1ull<<i))), wr);
}
if (i+1<w and !(cur&(1ull<<i)) and !(next&(1ull<<i)) and !(next&(1ull<<(i+1)))){
compute(i+1, w, ((cur|(1ull<<i))), (next|(1ull<<(i+1)|(1ull<<i))), wr);
}
if (cur&(1ull<<i)) compute(i+1, w, cur, next, wr);
}
}
void solve(){
ll w, h, k; cin >> w >> h >> k;
vector<vector<ll>> dp(h, vector<ll>(1<<w));
vector<ll> gr(h);
for (ll i=0; i<k; i++){
ll x, y; cin >> x >> y;
gr[y-1]|=(1<<(x-1));
}
compute(0, w, gr[0], gr[1], dp[1]);
for (ll i=1; i<h-1; i++){
for (ll j=0; j<(1<<w); j++){
if (dp[i][j]){
compute(0, w, j, gr[i+1], dp[i+1]);
}
}
}
if (dp.back()[(1<<w)-1]) cout << "YES\n";
else cout << "NO\n";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifdef LOCAL
auto start = chrono::high_resolution_clock::now();
#endif
ll testc=1;
// cin >> testc;
for (ll __c=1; __c<=testc; __c++) solve();
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
}
# | 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... |