#include <bits/stdc++.h>
using i64 = long long;
struct Point {
i64 x;
i64 y;
};
constexpr int N = 1 << 13;
int main() {
i64 W, H;
int K;
std::cin >> W >> H >> K;
std::vector<Point> points(K);
std::map<i64, int> mEx;
for (auto &[x, y] : points) {
std::cin >> x >> y;
--x;
--y;
mEx[y] |= 1 << x;
}
auto searchNext = [&](int s) {
static std::array<std::vector<int>, N> g;
static std::vector<int> seen(N);
if (seen[s]) {
return g[s];
}
seen[s] = true;
auto dfs = [&](auto &&self, int t, int b) -> void {
if (b >= W) {
g[s].push_back(t);
return;
}
if (s & (1 << b)) {
self(self, t, b + 1);
return;
}
if (b != 0) {
if (not (t & (1 << (b - 1)))) {
int newT = t;
newT |= 1 << (b - 1);
newT |= 1 << b;
self(self, newT, b + 1);
}
}
if (b != W - 1) {
if (s & (1 << (b + 1))) {
int newT = t;
newT |= 1 << b;
newT |= 1 << (b + 1);
self(self, newT, b + 2);
} else {
int newT = t;
newT |= 1 << b;
self(self, newT, b + 2);
newT = t;
newT |= 1 << (b + 1);
self(self, newT, b + 2);
}
}
};
dfs(dfs, 0, 0);
return g[s];
};
std::vector dp(1 << W, false);
dp[(1 << W) - 1] = true;
for (int i = 0; i < H; ++i) {
std::vector ndp(1 << W, false);
for (int s = 0; s < (1 << W); ++s) {
if (not dp[s]) {
continue;
}
const int b = mEx[i];
const auto g = searchNext(s);
for (const auto t : g) {
if ((t & b) != 0) {
continue;
}
ndp[t | b] = true;
}
}
dp = std::move(ndp);
}
std::cout << (dp[(1 << W) - 1] ? "YES" : "NO") << std::endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
688 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
30 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
280 ms |
1744 KB |
Output is correct |
17 |
Correct |
30 ms |
596 KB |
Output is correct |
18 |
Correct |
134 ms |
1116 KB |
Output is correct |
19 |
Correct |
3 ms |
596 KB |
Output is correct |
20 |
Correct |
303 ms |
1716 KB |
Output is correct |
21 |
Correct |
129 ms |
1004 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
564 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
333 ms |
1844 KB |
Output is correct |
26 |
Correct |
372 ms |
1748 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8029 ms |
66320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4271 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8053 ms |
397324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8038 ms |
66632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
688 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
30 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
280 ms |
1744 KB |
Output is correct |
17 |
Correct |
30 ms |
596 KB |
Output is correct |
18 |
Correct |
134 ms |
1116 KB |
Output is correct |
19 |
Correct |
3 ms |
596 KB |
Output is correct |
20 |
Correct |
303 ms |
1716 KB |
Output is correct |
21 |
Correct |
129 ms |
1004 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
564 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
333 ms |
1844 KB |
Output is correct |
26 |
Correct |
372 ms |
1748 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Execution timed out |
8029 ms |
66320 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |