#include "bits/stdc++.h"
using namespace std;
#define ar array
const int N = 15;
const int M = 1005;
int dp[2][N][1 << N];
int is[N][M];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m, k; cin>>n>>m>>k;
if(!k){
if((n % 3 == 0 && m % 2 == 0) || (n % 2 == 0 && m % 3 == 0)) cout<<"YES\n";
else cout<<"NO\n";
return 0;
}
vector<int> x(k), y(k);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
is[i][j] = 1;
}
}
for(int i=0;i<k;i++){
cin>>x[i]>>y[i]; x[i]--, y[i]--;
is[x[i]][y[i]] = 0;
}
int ch[4][2] = {
{0, 0},
{-1, 0},
{-1, 1},
{0, 1}
};
int P[4] = {1, 0, -1, 0}, mas[4] = {14, 13, 11, 7};
int mask = (!is[0][1]);
for(int i=0;i<n;i++){
if(!is[i][0]) mask |= (1 << (i + 1));
}
dp[0][1][mask] = 1;
for(int i=0;i+1<m;i++){
int c = i&1;
memset(dp[!c], 0, sizeof dp[!c]);
for(int j=1;j<n;j++){
for(int mask=0;mask < (1 << (n + 1));mask++){
if(!dp[c][j][mask]) continue;
int us = 0;
for(int t=0;t<4;t++){
us |= (is[j + ch[t][0]][i + ch[t][1]] & (t < 3 ? !(mask >> (j + P[t]) & 1) : 1)) << t;
}
for(int t=0;t<4;t++){
if((us & mas[t]) != mas[t]) continue;
int m2 = mask;
for(int l=0;l<4;l++){
if(mas[t] >> l & 1){
//~ assert(!(m2 >> (j + P[l]) & 1));
m2 |= (1 << (j + P[l]));
}
}
if(t == 1 && !(mask >> j & 1)) continue;
if(t == 3){
m2 ^= (1 << j);
m2 |= (!is[j][i + 1]) << j;
}
if(j + 1 < n){
dp[c][j + 1][m2] = 1;
} else if(m2 >> n & 1) {
m2 ^= (1 << n);
m2 = m2 << 1 | (!is[0][i + 2]);
dp[!c][1][m2] = 1;
}
}
if(mask >> j & 1){
int m2 = mask;
if(j + 1 < n){
m2 ^= (1 << j);
m2 |= (!is[j][i+1]) << j;
dp[c][j + 1][m2] = 1;
} else if(m2 >> n & 1) {
m2 ^= (1 << j) ^ (1 << n);
m2 |= (!is[j][i+1]) << j;
m2 = m2 << 1 | (!is[0][i + 2]);
dp[!c][1][m2] = 1;
}
}
}
}
}
if(dp[(m-1)&1][1][(1 << (n + 1)) - 1]) cout<<"YES\n";
else cout<<"NO\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
4164 KB |
Output is correct |
2 |
Correct |
43 ms |
4160 KB |
Output is correct |
3 |
Correct |
41 ms |
4156 KB |
Output is correct |
4 |
Correct |
39 ms |
4052 KB |
Output is correct |
5 |
Correct |
41 ms |
4180 KB |
Output is correct |
6 |
Correct |
47 ms |
4180 KB |
Output is correct |
7 |
Correct |
4 ms |
4180 KB |
Output is correct |
8 |
Correct |
64 ms |
4180 KB |
Output is correct |
9 |
Correct |
9 ms |
4204 KB |
Output is correct |
10 |
Correct |
11 ms |
4200 KB |
Output is correct |
11 |
Correct |
129 ms |
4196 KB |
Output is correct |
12 |
Correct |
14 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
3 ms |
4180 KB |
Output is correct |
15 |
Correct |
7 ms |
4180 KB |
Output is correct |
16 |
Correct |
1115 ms |
4200 KB |
Output is correct |
17 |
Correct |
176 ms |
4184 KB |
Output is correct |
18 |
Correct |
543 ms |
4208 KB |
Output is correct |
19 |
Correct |
61 ms |
4180 KB |
Output is correct |
20 |
Correct |
1108 ms |
4200 KB |
Output is correct |
21 |
Correct |
600 ms |
4196 KB |
Output is correct |
22 |
Correct |
63 ms |
4052 KB |
Output is correct |
23 |
Correct |
56 ms |
4180 KB |
Output is correct |
24 |
Correct |
55 ms |
4180 KB |
Output is correct |
25 |
Correct |
1226 ms |
4200 KB |
Output is correct |
26 |
Correct |
1313 ms |
4180 KB |
Output is correct |
27 |
Correct |
69 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
8268 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
8276 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
8320 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
4164 KB |
Output is correct |
2 |
Correct |
43 ms |
4160 KB |
Output is correct |
3 |
Correct |
41 ms |
4156 KB |
Output is correct |
4 |
Correct |
39 ms |
4052 KB |
Output is correct |
5 |
Correct |
41 ms |
4180 KB |
Output is correct |
6 |
Correct |
47 ms |
4180 KB |
Output is correct |
7 |
Correct |
4 ms |
4180 KB |
Output is correct |
8 |
Correct |
64 ms |
4180 KB |
Output is correct |
9 |
Correct |
9 ms |
4204 KB |
Output is correct |
10 |
Correct |
11 ms |
4200 KB |
Output is correct |
11 |
Correct |
129 ms |
4196 KB |
Output is correct |
12 |
Correct |
14 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
3 ms |
4180 KB |
Output is correct |
15 |
Correct |
7 ms |
4180 KB |
Output is correct |
16 |
Correct |
1115 ms |
4200 KB |
Output is correct |
17 |
Correct |
176 ms |
4184 KB |
Output is correct |
18 |
Correct |
543 ms |
4208 KB |
Output is correct |
19 |
Correct |
61 ms |
4180 KB |
Output is correct |
20 |
Correct |
1108 ms |
4200 KB |
Output is correct |
21 |
Correct |
600 ms |
4196 KB |
Output is correct |
22 |
Correct |
63 ms |
4052 KB |
Output is correct |
23 |
Correct |
56 ms |
4180 KB |
Output is correct |
24 |
Correct |
55 ms |
4180 KB |
Output is correct |
25 |
Correct |
1226 ms |
4200 KB |
Output is correct |
26 |
Correct |
1313 ms |
4180 KB |
Output is correct |
27 |
Correct |
69 ms |
4180 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |