/*input
2 3 0
*/
#pragma GCC optimize ("O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int W, H, K;
cin >> W >> H >> K;
map<int, int>A;
while (K--)
{
int x, y;
cin >> x >> y;
if (A.count(y) == 0)
A[y] = 0;
A[y] |= 1 << (x - 1);
}
bitset < 1 << 13 > gal;
gal[(1 << W) - 1] = true;
vector<int>X[1 << 13];
for (int i = 1; i <= H; i++)
{
bitset < 1 << 13 > gal_;
int msk = 0;
function<void(int, int, int)>dfs = [&](int i, int m1, int m2)
{
if (i == W - 1)
{
if (m1 == (1 << W) - 1)
X[msk].push_back(m2);
return;
}
for (int da : {0, 1})
{
for (int db : {0, 1})
{
int m[2] = {m1, m2};
bool ok = true;
for (int dx : {0, 1})
{
for (int dy : {0, 1})
{
if (dx == da && dy == db)
continue;
if ((m[dx] & (1 << (i + dy))) != 0)
ok = false;
m[dx] |= 1 << (i + dy);
}
}
if (ok)
dfs(i + 1, m[0], m[1]);
}
}
dfs(i + 1, m1, m2);
};
for (msk = 0; msk < (1 << W); msk++)
if (gal[msk])
{
if (X[msk].empty())
dfs(0, msk, 0);
for (int msk1 : X[msk])
if ((msk1 & A[i]) == 0)
gal_[msk1 | A[i]] = true;
}
gal = gal_;
}
if (gal[(1 << W) - 1])
cout << "YES\n";
else
cout << "NO\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
122 ms |
692 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
7 ms |
468 KB |
Output is correct |
11 |
Correct |
225 ms |
748 KB |
Output is correct |
12 |
Correct |
13 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
59 ms |
632 KB |
Output is correct |
16 |
Correct |
2714 ms |
2240 KB |
Output is correct |
17 |
Correct |
169 ms |
596 KB |
Output is correct |
18 |
Correct |
971 ms |
1132 KB |
Output is correct |
19 |
Correct |
9 ms |
468 KB |
Output is correct |
20 |
Correct |
3032 ms |
2344 KB |
Output is correct |
21 |
Correct |
1024 ms |
1356 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
7 ms |
540 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3592 ms |
2320 KB |
Output is correct |
26 |
Correct |
3623 ms |
2120 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8063 ms |
9056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8089 ms |
463644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8101 ms |
117568 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8087 ms |
9580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
122 ms |
692 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
7 ms |
468 KB |
Output is correct |
11 |
Correct |
225 ms |
748 KB |
Output is correct |
12 |
Correct |
13 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
59 ms |
632 KB |
Output is correct |
16 |
Correct |
2714 ms |
2240 KB |
Output is correct |
17 |
Correct |
169 ms |
596 KB |
Output is correct |
18 |
Correct |
971 ms |
1132 KB |
Output is correct |
19 |
Correct |
9 ms |
468 KB |
Output is correct |
20 |
Correct |
3032 ms |
2344 KB |
Output is correct |
21 |
Correct |
1024 ms |
1356 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
7 ms |
540 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3592 ms |
2320 KB |
Output is correct |
26 |
Correct |
3623 ms |
2120 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Execution timed out |
8063 ms |
9056 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |