#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=(1<<13)+7;
set<int>G[N];
bool DP[N],nDP[N];
int n,m,k;
void bt(int x,int p,int i,int y)
{
int X=x|p;
if(i==n)
{
if(X!=(1<<n)-1) return ;
G[x].insert(y);
return ;
}
bt(x,p,i+1,y);
if(i<n-1)
{
if(!(X&(1<<i))&&!(X&(1<<(i+1)))&&!(y&(1<<(i+1)))) bt(x,p|(1<<i)|(1<<(i+1)),i+1,y|(1<<(i+1)));
if(!(X&(1<<i))&&!(X&(1<<(i+1)))&&!(y&(1<<i))) bt(x,p|(1<<i)|(1<<(i+1)),i+1,y|(1<<i));
if(!(X&(1<<i))&&!(y&(1<<(i+1)))&&!(y&(1<<i))) bt(x,p|(1<<i),i+1,y|(1<<i)|(1<<(i+1)));
}
if(i>0&&!(X&(1<<i))&&!(y&(1<<(i-1)))&&!(y&(1<<i))) bt(x,p|(1<<i),i+1,y|(1<<i)|(1<<(i-1)));
}
set<int>S;
map<int,vector<int>>M;
vector<int>G3[8][2];
vector<int>G2[4][3];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=0;i<(1<<n);i++) bt(i,0,0,0);
if(n==3)
{
for(int c=0;c<8;c++)
{
memset(DP,0,sizeof DP);
DP[c]=1;
for(int j=0; j<2; j++)
{
memset(nDP,0,sizeof nDP);
for(int i=0; i<(1<<n); i++)
{
if(!DP[i]) continue;
for(auto x:G[i]) nDP[x]=1;
}
for(int i=0;i<(1<<n);i++) DP[i]=nDP[i];
for(int i=0;i<(1<<n);i++)
{
if(DP[i]) G3[c][j^1].pb(i);
}
}
}
}
if(n==2)
{
for(int c=0;c<4;c++)
{
memset(DP,0,sizeof DP);
DP[c]=1;
for(int j=0; j<3; j++)
{
memset(nDP,0,sizeof nDP);
for(int i=0; i<(1<<n); i++)
{
if(!DP[i]) continue;
for(auto x:G[i]) nDP[x]=1;
}
for(int i=0;i<(1<<n);i++) DP[i]=nDP[i];
for(int i=0;i<(1<<n);i++)
{
if(DP[i]) G3[c][(j+1)%3].pb(i);
}
}
}
}
for(int i=0;i<k;i++)
{
int x,y;
cin>>x>>y;
S.insert(y);
M[y].pb(x);
}
S.insert(m);
memset(DP,0,sizeof DP);
memset(nDP,0,sizeof nDP);
DP[0]=1;
int l=1;
for(auto p:S)
{
int X=0;
for(auto c:M[p]) X|=(1<<(c-1));
if(p-l>15)
{
if(n>3)
{
vector<bool>is(3,0);
for(int i=0; i<(1<<n); i++)
{
if(DP[i]) is[__builtin_popcount(i)%3]=1;
}
for(int i=0; i<(1<<n); i++)
{
if(is[((p-l)%3*n%3+__builtin_popcount(i))%3]) DP[i]=1;
else DP[i]=0;
}
}
else if(n==3)
{
memset(nDP,0,sizeof nDP);
for(int i=0;i<(1<<n);i++)
{
if(!DP[i]) continue;
for(auto x:G3[i][(p-l)%2]) nDP[x]=1;
}
for(int i=0;i<(1<<n);i++) DP[i]=nDP[i];
}
else if(n==2)
{
memset(nDP,0,sizeof nDP);
for(int i=0;i<(1<<n);i++)
{
if(!DP[i]) continue;
for(auto x:G2[i][(p-l)%3]) nDP[x]=1;
}
for(int i=0;i<(1<<n);i++) DP[i]=nDP[i];
}
}
else
{
for(int j=0;j<p-l;j++)
{
memset(nDP,0,sizeof nDP);
for(int i=0; i<(1<<n); i++)
{
if(!DP[i]) continue;
for(auto x:G[i]) nDP[x]=1;
}
for(int i=0;i<(1<<n);i++) DP[i]=nDP[i];
}
}
memset(nDP,0,sizeof nDP);
for(int i=0;i<(1<<n);i++)
{
if(DP[i]&&!(i&X)) nDP[i|X]=1;
}
for(int i=0;i<(1<<n);i++) DP[i]=nDP[i];
l=p;
}
if(DP[(1<<n)-1]) cout<<"YES";
else cout<<"NO";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
71 ms |
4044 KB |
Output is correct |
6 |
Correct |
20 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
708 KB |
Output is correct |
13 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
2 ms |
724 KB |
Output is correct |
36 |
Correct |
1 ms |
724 KB |
Output is correct |
37 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
77 ms |
4056 KB |
Output is correct |
5 |
Correct |
23 ms |
1892 KB |
Output is correct |
6 |
Correct |
31 ms |
1916 KB |
Output is correct |
7 |
Correct |
8 ms |
1216 KB |
Output is correct |
8 |
Correct |
8 ms |
1108 KB |
Output is correct |
9 |
Correct |
9 ms |
1208 KB |
Output is correct |
10 |
Correct |
12 ms |
1108 KB |
Output is correct |
11 |
Correct |
73 ms |
3976 KB |
Output is correct |
12 |
Correct |
21 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
852 KB |
Output is correct |
14 |
Correct |
70 ms |
4040 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
7 ms |
1108 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
928 KB |
Output is correct |
20 |
Correct |
78 ms |
4020 KB |
Output is correct |
21 |
Correct |
23 ms |
2004 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
4 ms |
852 KB |
Output is correct |
24 |
Correct |
260 ms |
9636 KB |
Output is correct |
25 |
Correct |
78 ms |
4092 KB |
Output is correct |
26 |
Correct |
265 ms |
9688 KB |
Output is correct |
27 |
Correct |
261 ms |
9624 KB |
Output is correct |
28 |
Correct |
291 ms |
9672 KB |
Output is correct |
29 |
Correct |
290 ms |
9816 KB |
Output is correct |
30 |
Correct |
493 ms |
9764 KB |
Output is correct |
31 |
Correct |
263 ms |
9616 KB |
Output is correct |
32 |
Correct |
279 ms |
9668 KB |
Output is correct |
33 |
Correct |
75 ms |
4108 KB |
Output is correct |
34 |
Correct |
263 ms |
9676 KB |
Output is correct |
35 |
Correct |
265 ms |
9676 KB |
Output is correct |
36 |
Correct |
284 ms |
9688 KB |
Output is correct |
37 |
Correct |
81 ms |
4092 KB |
Output is correct |
38 |
Correct |
89 ms |
4048 KB |
Output is correct |
39 |
Correct |
27 ms |
1952 KB |
Output is correct |
40 |
Correct |
270 ms |
9672 KB |
Output is correct |
41 |
Correct |
28 ms |
2004 KB |
Output is correct |
42 |
Correct |
260 ms |
9648 KB |
Output is correct |
43 |
Correct |
459 ms |
9684 KB |
Output is correct |
44 |
Correct |
297 ms |
9752 KB |
Output is correct |
45 |
Correct |
261 ms |
9616 KB |
Output is correct |
46 |
Correct |
76 ms |
4104 KB |
Output is correct |
47 |
Correct |
3006 ms |
9696 KB |
Output is correct |
48 |
Correct |
2576 ms |
9688 KB |
Output is correct |
49 |
Correct |
767 ms |
9568 KB |
Output is correct |
50 |
Correct |
104 ms |
2004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |