#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()
const int maxW = 13;
int W, H, K;
map<int, int> blocked;
bitset<1 << maxW> dp[2];
bitset<1 << maxW> mat[1 << maxW];
void dfs(int idx, int base, int next, bitset<1 << maxW> &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);
}
for (int i = 0; i < 1 << W; ++i)
dfs(0, i, 0, mat[i]);
dp[0] = 0;
dp[0][0] = true;
for (int i = 0; i < H; ++i)
{
int ii = i & 1;
int ni = ii ^ 1;
dp[ni] = 0;
for (int j = 0; j < sz(dp[ii]); ++j)
{
if (!dp[ii][j])
continue;
if (j & blocked[i])
continue;
dp[ni] |= mat[j | blocked[i]];
}
}
if (dp[H & 1][0])
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
356 KB |
Output is correct |
4 |
Correct |
6 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
11 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
16 ms |
4436 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
31 ms |
4436 KB |
Output is correct |
12 |
Correct |
3 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
4436 KB |
Output is correct |
16 |
Correct |
288 ms |
8556 KB |
Output is correct |
17 |
Correct |
53 ms |
1364 KB |
Output is correct |
18 |
Correct |
154 ms |
4448 KB |
Output is correct |
19 |
Correct |
10 ms |
468 KB |
Output is correct |
20 |
Correct |
294 ms |
8560 KB |
Output is correct |
21 |
Correct |
161 ms |
4464 KB |
Output is correct |
22 |
Correct |
7 ms |
340 KB |
Output is correct |
23 |
Correct |
10 ms |
488 KB |
Output is correct |
24 |
Correct |
7 ms |
392 KB |
Output is correct |
25 |
Correct |
321 ms |
8560 KB |
Output is correct |
26 |
Correct |
315 ms |
8556 KB |
Output is correct |
27 |
Correct |
8 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8010 ms |
22920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8022 ms |
59784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8067 ms |
52456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8074 ms |
23380 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
356 KB |
Output is correct |
4 |
Correct |
6 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
11 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
16 ms |
4436 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
31 ms |
4436 KB |
Output is correct |
12 |
Correct |
3 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
4436 KB |
Output is correct |
16 |
Correct |
288 ms |
8556 KB |
Output is correct |
17 |
Correct |
53 ms |
1364 KB |
Output is correct |
18 |
Correct |
154 ms |
4448 KB |
Output is correct |
19 |
Correct |
10 ms |
468 KB |
Output is correct |
20 |
Correct |
294 ms |
8560 KB |
Output is correct |
21 |
Correct |
161 ms |
4464 KB |
Output is correct |
22 |
Correct |
7 ms |
340 KB |
Output is correct |
23 |
Correct |
10 ms |
488 KB |
Output is correct |
24 |
Correct |
7 ms |
392 KB |
Output is correct |
25 |
Correct |
321 ms |
8560 KB |
Output is correct |
26 |
Correct |
315 ms |
8556 KB |
Output is correct |
27 |
Correct |
8 ms |
340 KB |
Output is correct |
28 |
Execution timed out |
8010 ms |
22920 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |