#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;
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);
for(int i=0;i<k;i++)
{
int x,y;
cin>>x>>y;
S.insert(y);
M[y].pb(x);
}
S.insert(m);
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)
{
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
{
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 |
Correct |
1 ms |
596 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 |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
708 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
73 ms |
4044 KB |
Output is correct |
9 |
Correct |
22 ms |
1964 KB |
Output is correct |
10 |
Correct |
2 ms |
840 KB |
Output is correct |
11 |
Correct |
73 ms |
4036 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
712 KB |
Output is correct |
15 |
Correct |
70 ms |
4164 KB |
Output is correct |
16 |
Correct |
1183 ms |
9780 KB |
Output is correct |
17 |
Correct |
14 ms |
1108 KB |
Output is correct |
18 |
Correct |
282 ms |
4192 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
842 ms |
9764 KB |
Output is correct |
21 |
Correct |
216 ms |
4104 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
383 ms |
9580 KB |
Output is correct |
26 |
Correct |
730 ms |
9768 KB |
Output is correct |
27 |
Correct |
1 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 |
712 KB |
Output is correct |
3 |
Correct |
1 ms |
708 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
71 ms |
4084 KB |
Output is correct |
6 |
Correct |
19 ms |
1992 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 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 |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
17 |
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 |
596 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 |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
708 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 |
2 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 |
712 KB |
Output is correct |
22 |
Correct |
1 ms |
712 KB |
Output is correct |
23 |
Correct |
1 ms |
708 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
708 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 |
716 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 |
81 ms |
4056 KB |
Output is correct |
5 |
Correct |
26 ms |
1876 KB |
Output is correct |
6 |
Correct |
29 ms |
1940 KB |
Output is correct |
7 |
Correct |
8 ms |
1108 KB |
Output is correct |
8 |
Correct |
8 ms |
1108 KB |
Output is correct |
9 |
Correct |
9 ms |
1100 KB |
Output is correct |
10 |
Correct |
11 ms |
1108 KB |
Output is correct |
11 |
Correct |
69 ms |
4072 KB |
Output is correct |
12 |
Correct |
22 ms |
1868 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
75 ms |
4044 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
712 KB |
Output is correct |
17 |
Correct |
8 ms |
1108 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
3 ms |
852 KB |
Output is correct |
20 |
Correct |
75 ms |
4040 KB |
Output is correct |
21 |
Correct |
25 ms |
2004 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
4 ms |
840 KB |
Output is correct |
24 |
Correct |
282 ms |
9832 KB |
Output is correct |
25 |
Correct |
96 ms |
4132 KB |
Output is correct |
26 |
Correct |
296 ms |
9720 KB |
Output is correct |
27 |
Correct |
297 ms |
9628 KB |
Output is correct |
28 |
Correct |
279 ms |
9648 KB |
Output is correct |
29 |
Correct |
293 ms |
9684 KB |
Output is correct |
30 |
Correct |
471 ms |
9664 KB |
Output is correct |
31 |
Correct |
291 ms |
9688 KB |
Output is correct |
32 |
Correct |
287 ms |
9664 KB |
Output is correct |
33 |
Correct |
76 ms |
4076 KB |
Output is correct |
34 |
Correct |
283 ms |
9688 KB |
Output is correct |
35 |
Correct |
266 ms |
9700 KB |
Output is correct |
36 |
Correct |
270 ms |
9692 KB |
Output is correct |
37 |
Correct |
75 ms |
3976 KB |
Output is correct |
38 |
Correct |
89 ms |
4044 KB |
Output is correct |
39 |
Correct |
30 ms |
2008 KB |
Output is correct |
40 |
Correct |
270 ms |
9692 KB |
Output is correct |
41 |
Correct |
30 ms |
1904 KB |
Output is correct |
42 |
Correct |
269 ms |
9832 KB |
Output is correct |
43 |
Correct |
556 ms |
9684 KB |
Output is correct |
44 |
Correct |
285 ms |
9684 KB |
Output is correct |
45 |
Correct |
268 ms |
9564 KB |
Output is correct |
46 |
Correct |
81 ms |
4052 KB |
Output is correct |
47 |
Correct |
3182 ms |
9692 KB |
Output is correct |
48 |
Correct |
2360 ms |
9692 KB |
Output is correct |
49 |
Correct |
830 ms |
9688 KB |
Output is correct |
50 |
Correct |
114 ms |
2000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 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 |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
708 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
73 ms |
4044 KB |
Output is correct |
9 |
Correct |
22 ms |
1964 KB |
Output is correct |
10 |
Correct |
2 ms |
840 KB |
Output is correct |
11 |
Correct |
73 ms |
4036 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
712 KB |
Output is correct |
15 |
Correct |
70 ms |
4164 KB |
Output is correct |
16 |
Correct |
1183 ms |
9780 KB |
Output is correct |
17 |
Correct |
14 ms |
1108 KB |
Output is correct |
18 |
Correct |
282 ms |
4192 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
842 ms |
9764 KB |
Output is correct |
21 |
Correct |
216 ms |
4104 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
383 ms |
9580 KB |
Output is correct |
26 |
Correct |
730 ms |
9768 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 |
712 KB |
Output is correct |
30 |
Correct |
1 ms |
708 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
71 ms |
4084 KB |
Output is correct |
33 |
Correct |
19 ms |
1992 KB |
Output is correct |
34 |
Correct |
7 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
36 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |