#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int W, H, K;
map<int, int> blocked;
vb dp[2];
void dfs(int idx, int base, int next, vb &nextdp)
{
if (idx == W)
{
nextdp[next] = true;
return;
}
if (base & (1 << idx))
dfs(idx + 1, base, next, nextdp);
else
{
// _X my pos: 1 << idx
// TT
// _T
if (idx < W - 1 && ((3 << idx) & next) == 0)
dfs(idx + 1, base | (1 << idx), next | (3 << idx), nextdp);
// _TT
// _T_
if (idx > 0 && ((3 << (idx - 1)) & next) == 0)
dfs(idx + 1, base | (1 << idx), next | (3 << (idx - 1)), nextdp);
// T_
// TT
if (idx < W - 1 && (base & (3 << idx)) == 0 && (next & (2 << idx)) == 0)
dfs(idx + 2, base | (3 << idx), next | (2 << idx), nextdp);
// _T
// TT
if (idx < W - 1 && (base & (3 << idx)) == 0 && (next & (1 << idx)) == 0)
dfs(idx + 2, base | (3 << idx), next | (1 << idx), nextdp);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> W >> H >> K;
for (int k = 0, x, y; k < K; ++k)
{
cin >> x >> y;
--x, --y;
blocked[y] = blocked[y] | (1 << x);
}
dp[0] = vb(1 << W, false);
dp[0][0] = true;
for (int i = 0; i < H; ++i)
{
int ii = i & 1;
int ni = ii ^ 1;
dp[ni] = vb(1 << W, false);
for (int j = 0; j < sz(dp[ii]); ++j)
{
if (!dp[ii][j])
continue;
if (j & blocked[i])
continue;
dfs(0, j | blocked[i], 0, dp[ni]);
}
}
if (dp[H & 1][0])
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
280 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
59 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
119 ms |
320 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1255 ms |
464 KB |
Output is correct |
17 |
Correct |
100 ms |
348 KB |
Output is correct |
18 |
Correct |
532 ms |
324 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
1332 ms |
472 KB |
Output is correct |
21 |
Correct |
523 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
324 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1470 ms |
452 KB |
Output is correct |
26 |
Correct |
1505 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8047 ms |
34132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6816 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8048 ms |
213720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8041 ms |
31432 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
280 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
59 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
119 ms |
320 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1255 ms |
464 KB |
Output is correct |
17 |
Correct |
100 ms |
348 KB |
Output is correct |
18 |
Correct |
532 ms |
324 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
1332 ms |
472 KB |
Output is correct |
21 |
Correct |
523 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
324 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1470 ms |
452 KB |
Output is correct |
26 |
Correct |
1505 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Execution timed out |
8047 ms |
34132 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |