#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
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;
typedef bitset<1 << maxW> bs;
typedef vector<bs> vbs;
typedef vector<vbs> vvbs;
int W, H, K;
map<int, int> blocked;
vbs mod;
vi group;
vi degin, degout, deg;
vvi adj;
void dfs(int idx, int base, int next, set<int> &nextdp)
{
if (idx == W)
{
nextdp.insert(next);
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);
}
}
void step(bs &base, int block = 0)
{
bs re = 0;
for (int j = 0; j < 1 << W; ++j)
{
if (!base[j])
continue;
if (j & block)
continue;
for (int u : adj[j | block])
re[u] = 1;
}
swap(base, re);
}
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);
}
degin.assign(1 << W, 0), degout.assign(1 << W, 0), deg.assign(1 << W, 0);
adj.resize(1 << W);
for (int i = 0; i < 1 << W; ++i)
{
set<int> tmp;
dfs(0, i, 0, tmp);
degout[i] = sz(tmp);
for (int u : tmp)
adj[i].push_back(u), ++degin[u];
}
for (int i = 0; i < 1 << W; ++i)
deg[i] = max(degin[i], degout[i]);
group.assign(1 << W, -1);
mod.assign(3, 0);
if (W % 3 == 0)
{
int idx = 0;
for (int i = 0; i < 1 << W; ++i)
{
if (group[i] != -1 || degout[i] == 0)
continue;
bs start = 0;
start[i] = 1;
for (int j = 0; j < 12; ++j)
step(start);
if (degin[i] == 0)
{
int j = 0;
while (!start[j])
++j;
group[i] = group[j];
continue;
}
mod[idx] = start;
for (int j = 0; j < (1 << W); ++j)
if (start[j])
group[j] = idx;
++idx;
}
assert(idx == 3);
}
else
{
bs start = 0;
start[0] = 1;
for (int j = 0; j < 12; ++j)
step(start);
for (int idx = 0; idx < 3; ++idx)
{
for (int i = 0; i < 1 << W; ++i)
if (start[i])
group[i] = idx;
mod[idx] = start;
step(start);
}
}
bs start = 0;
start[0] = 1;
blocked[H - 1] = blocked[H - 1] | 0;
int h = 0;
for (pii p : blocked)
{
int delta = p.first - h;
if (delta >= 11)
{
set<int> G;
if (W % 3 == 0)
{
for (int i = 0; i < 1 << W; ++i)
if (start[i])
G.insert(group[i]);
}
else
{
for (int i = 0; i < 1 << W; ++i)
if (start[i])
G.insert((group[i] + delta) % 3);
}
start = 0;
for (int g : G)
start |= mod[g];
h = p.first;
}
else
{
for (; h < p.first; ++h)
step(start);
}
step(start, p.second);
++h;
}
if (start[0])
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
284 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
12 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
5 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
884 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
13 ms |
820 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
14 ms |
844 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
44 ms |
1740 KB |
Output is correct |
25 |
Correct |
18 ms |
856 KB |
Output is correct |
26 |
Correct |
38 ms |
1800 KB |
Output is correct |
27 |
Correct |
38 ms |
1748 KB |
Output is correct |
28 |
Correct |
26 ms |
1760 KB |
Output is correct |
29 |
Correct |
28 ms |
1784 KB |
Output is correct |
30 |
Correct |
45 ms |
1740 KB |
Output is correct |
31 |
Correct |
26 ms |
1768 KB |
Output is correct |
32 |
Correct |
27 ms |
1744 KB |
Output is correct |
33 |
Correct |
13 ms |
956 KB |
Output is correct |
34 |
Correct |
31 ms |
1804 KB |
Output is correct |
35 |
Correct |
38 ms |
1824 KB |
Output is correct |
36 |
Correct |
38 ms |
1728 KB |
Output is correct |
37 |
Correct |
10 ms |
852 KB |
Output is correct |
38 |
Correct |
14 ms |
932 KB |
Output is correct |
39 |
Correct |
6 ms |
468 KB |
Output is correct |
40 |
Correct |
34 ms |
1808 KB |
Output is correct |
41 |
Correct |
7 ms |
596 KB |
Output is correct |
42 |
Correct |
34 ms |
1728 KB |
Output is correct |
43 |
Correct |
43 ms |
1740 KB |
Output is correct |
44 |
Correct |
35 ms |
1796 KB |
Output is correct |
45 |
Correct |
33 ms |
1740 KB |
Output is correct |
46 |
Correct |
11 ms |
880 KB |
Output is correct |
47 |
Correct |
233 ms |
1772 KB |
Output is correct |
48 |
Correct |
184 ms |
1748 KB |
Output is correct |
49 |
Correct |
74 ms |
1812 KB |
Output is correct |
50 |
Correct |
15 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |