This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
using VI = vector<int>;
int W;
vector<vector<int>> G;
int dfs(int i, int mask, int t) {
if (i == W) return G[mask].emplace_back(t), 0;
if (mask & 1 << i) return dfs(i + 1, mask, t), 0;
if (i && !(t & 1 << (i - 1)) && !(t & 1 << i))
dfs(i + 1, mask, t | 1 << i | 1 << (i - 1));
if (i + 1 < W && !(mask & 1 << (i + 1)) && !(t & 1 << (i + 1)))
dfs(i + 2, mask, t | 1 << (i + 1));
if (i + 1 < W && !(t & 1 << i) && !(mask & 1 << (i + 1)))
dfs(i + 2, mask, t | 1 << i);
if (i + 1 < W && !(t & 1 << i) && !(t & (1 << (i + 1))))
dfs(i + 1, mask, t | 1 << i | 1 << (i + 1));
return 0;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
for (int h, k, SW; cin >> W >> h >> k; G.clear()) {
SW = 1 << W, G.resize(SW);
_for(mask, 0, SW) dfs(0, mask, 0);
map<int, int> mp{{1, 0}, {h, 0}};
for (int i = 0, x, y; i < k; i++) cin >> x >> y, x--, mp[y] |= 1 << x;
vector<int> a(SW), b(SW);
a[0] = 1;
for (auto it = mp.begin();;) {
int y = it->first, t = it->second;
_for(i, 0, SW) if (!(i & t)) b[i | t] |= a[i];
swap(a, b), fill(begin(b), end(b), 0);
if (++it == mp.end()) break;
int u = it->first - y;
if (u >= 12) u -= (u - 12) / 6 * 6;
while (u--) {
_for(i, 0, SW) for (int j : G[i]) b[j] |= a[i];
swap(a, b), fill(begin(b), end(b), 0);
}
}
cout << (a[SW - 1] ? "YES\n" : "NO\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... |