#include <bits/stdc++.h>
using namespace std;
const int MAX_W = 13;
const int MAX_N = (1 << MAX_W);
map<int, int> conf;
bitset<MAX_N> adj[MAX_N];
bool hasBit( int mask, int i ) {
return ((mask >> i) & 1);
}
int main() {
int w, h, k;
cin >> w >> h >> k;
conf[0] = conf[h - 1] = 0;
for ( int i = 0; i < k; i++ ) {
int l, c;
cin >> l >> c;
l--;
c--;
conf[c] += (1 << l);
}
int n = (1 << w);
for ( int mask = 0; mask < n; mask++ ) {
vector<int> prvVec1 = { 0 }, prvVec2 = { 0 };
for ( int i = 0; i < w; i++ ) {
vector<int> vec;
if ( hasBit( mask, i ) ) {
for ( int m: prvVec1 )
vec.push_back( m );
} else {
for ( int m: prvVec1 ) {
if ( i >= 1 && !hasBit( m, i - 1 ) && !hasBit( m, i ) )
vec.push_back( m + (1 << (i - 1)) + (1 << i) );
if ( i <= w - 2 && !hasBit( m, i ) && !hasBit( m, i + 1 ) )
vec.push_back( m + (1 << i) + (1 << (i + 1)) );
}
if ( i >= 1 && !hasBit( mask, i - 1 ) ) {
for ( int m: prvVec2 ) {
if ( !hasBit( m, i - 1 ) )
vec.push_back( m + (1 << (i - 1)) );
if ( !hasBit( m, i ) )
vec.push_back( m + (1 << i) );
}
}
}
prvVec2 = prvVec1;
prvVec1 = vec;
}
for ( int m: prvVec1 )
adj[mask][m] = 1;
}
bitset<MAX_N> pos;
pos[conf[0]] = true;
for ( int j = 1; j < h; j++ ) {
bitset<MAX_N> newPos;
for ( int m = 0; m < n; m++ ) {
if ( pos[m] )
newPos |= adj[m];
}
pos.reset();
for ( int m = 0; m < n; m++ ) {
if ( (conf[j] & m) == 0 )
pos[conf[j] | m] = newPos[m];
}
}
cout << (pos[n - 1] ? "YES\n" : "NO\n");
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
23 ms |
4760 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
11 |
Correct |
41 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
2652 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
9 ms |
4700 KB |
Output is correct |
16 |
Correct |
378 ms |
8688 KB |
Output is correct |
17 |
Correct |
51 ms |
2700 KB |
Output is correct |
18 |
Correct |
189 ms |
4760 KB |
Output is correct |
19 |
Correct |
6 ms |
604 KB |
Output is correct |
20 |
Correct |
430 ms |
8712 KB |
Output is correct |
21 |
Correct |
200 ms |
4748 KB |
Output is correct |
22 |
Correct |
2 ms |
444 KB |
Output is correct |
23 |
Correct |
6 ms |
380 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
475 ms |
8704 KB |
Output is correct |
26 |
Correct |
465 ms |
8696 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8045 ms |
16140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8036 ms |
288960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8050 ms |
96796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8029 ms |
16312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
23 ms |
4760 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
11 |
Correct |
41 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
2652 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
9 ms |
4700 KB |
Output is correct |
16 |
Correct |
378 ms |
8688 KB |
Output is correct |
17 |
Correct |
51 ms |
2700 KB |
Output is correct |
18 |
Correct |
189 ms |
4760 KB |
Output is correct |
19 |
Correct |
6 ms |
604 KB |
Output is correct |
20 |
Correct |
430 ms |
8712 KB |
Output is correct |
21 |
Correct |
200 ms |
4748 KB |
Output is correct |
22 |
Correct |
2 ms |
444 KB |
Output is correct |
23 |
Correct |
6 ms |
380 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
475 ms |
8704 KB |
Output is correct |
26 |
Correct |
465 ms |
8696 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Execution timed out |
8045 ms |
16140 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |