#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m;
int a[200005],b[200005],c[200005],d[200005];
bool dp[200005][10][10];
int mrg[15][15][2];
int main(){
for(int t=0;t<2;t++){
for(int p=0;p<15;p++){
for(int q=0;q<15;q++){
int ap=p/3,bp=p%3;
int aq=q/3,bq=q%3;
int a,b;
if(t==0) a=min(ap,aq),b=min(bp,bq);
if(t==1) a=max(ap,aq),b=max(bp,bq);
mrg[p][q][t]=a*3+b;
}
}
}
n=readint(); m=readint();
for(int i=1;i<=n;i++) a[i]=readint(),b[i]=readint();
for(int j=1;j<=m;j++){
int x=readint(),y=readint();
for(int i=1;i<=n;i++){
c[i]=(a[i]<x?0:(a[i]==x?1:2));
d[i]=(b[i]<y?0:(b[i]==y?1:2));
}
for(int i=1;i<=n;i++){
for(int p=0;p<10;p++){
for(int q=0;q<10;q++){
dp[i][p][q]=false;
}
}
}
dp[1][c[1]*3+d[1]][9]=true;
for(int i=2;i<=n;i++){
int val=c[i]*3+d[i];
for(int p=0;p<9;p++){
for(int q=0;q<10;q++){
if(!dp[i-1][p][q]) continue;
vector<int> cards;
if(q==9){
dp[i][p][val]=true;
}
if(q==9){
dp[i][mrg[p][val][0]][9]=true;
dp[i][mrg[p][val][1]][9]=true;
}
if(q!=9){
dp[i][p][mrg[q][val][0]]=true;
dp[i][p][mrg[q][val][1]]=true;
dp[i][mrg[p][mrg[q][val][0]][0]][9]=true;
dp[i][mrg[p][mrg[q][val][1]][0]][9]=true;
dp[i][mrg[p][mrg[q][val][0]][1]][9]=true;
dp[i][mrg[p][mrg[q][val][1]][1]][9]=true;
}
}
}
}
if(dp[n][4][9]) printf("%d ",j);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2472 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2492 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |
34 |
Correct |
0 ms |
2492 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2472 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2492 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |
34 |
Correct |
0 ms |
2492 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2652 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
3 ms |
2540 KB |
Output is correct |
49 |
Correct |
4 ms |
2652 KB |
Output is correct |
50 |
Correct |
3 ms |
4700 KB |
Output is correct |
51 |
Correct |
3 ms |
4700 KB |
Output is correct |
52 |
Correct |
3 ms |
2652 KB |
Output is correct |
53 |
Correct |
3 ms |
4700 KB |
Output is correct |
54 |
Correct |
4 ms |
4596 KB |
Output is correct |
55 |
Correct |
4 ms |
2720 KB |
Output is correct |
56 |
Correct |
4 ms |
4600 KB |
Output is correct |
57 |
Correct |
5 ms |
4700 KB |
Output is correct |
58 |
Correct |
3 ms |
4696 KB |
Output is correct |
59 |
Correct |
3 ms |
4700 KB |
Output is correct |
60 |
Correct |
2 ms |
4700 KB |
Output is correct |
61 |
Correct |
5 ms |
4788 KB |
Output is correct |
62 |
Correct |
3 ms |
4696 KB |
Output is correct |
63 |
Correct |
3 ms |
4700 KB |
Output is correct |
64 |
Correct |
3 ms |
4700 KB |
Output is correct |
65 |
Correct |
2 ms |
4700 KB |
Output is correct |
66 |
Correct |
2 ms |
4700 KB |
Output is correct |
67 |
Correct |
4 ms |
4544 KB |
Output is correct |
68 |
Correct |
3 ms |
4760 KB |
Output is correct |
69 |
Correct |
2 ms |
4700 KB |
Output is correct |
70 |
Correct |
3 ms |
4548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2472 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2492 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |
34 |
Correct |
0 ms |
2492 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2652 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
3 ms |
2540 KB |
Output is correct |
49 |
Correct |
4 ms |
2652 KB |
Output is correct |
50 |
Correct |
3 ms |
4700 KB |
Output is correct |
51 |
Correct |
3 ms |
4700 KB |
Output is correct |
52 |
Correct |
3 ms |
2652 KB |
Output is correct |
53 |
Correct |
3 ms |
4700 KB |
Output is correct |
54 |
Correct |
4 ms |
4596 KB |
Output is correct |
55 |
Correct |
4 ms |
2720 KB |
Output is correct |
56 |
Correct |
4 ms |
4600 KB |
Output is correct |
57 |
Correct |
5 ms |
4700 KB |
Output is correct |
58 |
Correct |
3 ms |
4696 KB |
Output is correct |
59 |
Correct |
3 ms |
4700 KB |
Output is correct |
60 |
Correct |
2 ms |
4700 KB |
Output is correct |
61 |
Correct |
5 ms |
4788 KB |
Output is correct |
62 |
Correct |
3 ms |
4696 KB |
Output is correct |
63 |
Correct |
3 ms |
4700 KB |
Output is correct |
64 |
Correct |
3 ms |
4700 KB |
Output is correct |
65 |
Correct |
2 ms |
4700 KB |
Output is correct |
66 |
Correct |
2 ms |
4700 KB |
Output is correct |
67 |
Correct |
4 ms |
4544 KB |
Output is correct |
68 |
Correct |
3 ms |
4760 KB |
Output is correct |
69 |
Correct |
2 ms |
4700 KB |
Output is correct |
70 |
Correct |
3 ms |
4548 KB |
Output is correct |
71 |
Correct |
204 ms |
23364 KB |
Output is correct |
72 |
Correct |
217 ms |
23636 KB |
Output is correct |
73 |
Correct |
227 ms |
26056 KB |
Output is correct |
74 |
Correct |
265 ms |
26192 KB |
Output is correct |
75 |
Correct |
261 ms |
26680 KB |
Output is correct |
76 |
Correct |
256 ms |
26956 KB |
Output is correct |
77 |
Correct |
269 ms |
26192 KB |
Output is correct |
78 |
Correct |
278 ms |
26708 KB |
Output is correct |
79 |
Correct |
291 ms |
26960 KB |
Output is correct |
80 |
Correct |
400 ms |
25364 KB |
Output is correct |
81 |
Correct |
419 ms |
25572 KB |
Output is correct |
82 |
Correct |
451 ms |
26064 KB |
Output is correct |
83 |
Correct |
241 ms |
25428 KB |
Output is correct |
84 |
Correct |
154 ms |
25400 KB |
Output is correct |
85 |
Correct |
152 ms |
25420 KB |
Output is correct |
86 |
Correct |
335 ms |
26968 KB |
Output is correct |
87 |
Correct |
219 ms |
23896 KB |
Output is correct |
88 |
Correct |
141 ms |
23900 KB |
Output is correct |
89 |
Correct |
180 ms |
24020 KB |
Output is correct |
90 |
Correct |
165 ms |
23896 KB |
Output is correct |
91 |
Correct |
183 ms |
24028 KB |
Output is correct |
92 |
Correct |
167 ms |
24024 KB |
Output is correct |
93 |
Correct |
208 ms |
23900 KB |
Output is correct |
94 |
Correct |
163 ms |
24008 KB |
Output is correct |
95 |
Correct |
234 ms |
23896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2472 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2492 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |
34 |
Correct |
0 ms |
2492 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2652 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
3 ms |
2540 KB |
Output is correct |
49 |
Correct |
4 ms |
2652 KB |
Output is correct |
50 |
Correct |
3 ms |
4700 KB |
Output is correct |
51 |
Correct |
3 ms |
4700 KB |
Output is correct |
52 |
Correct |
3 ms |
2652 KB |
Output is correct |
53 |
Correct |
3 ms |
4700 KB |
Output is correct |
54 |
Correct |
4 ms |
4596 KB |
Output is correct |
55 |
Correct |
4 ms |
2720 KB |
Output is correct |
56 |
Correct |
4 ms |
4600 KB |
Output is correct |
57 |
Correct |
5 ms |
4700 KB |
Output is correct |
58 |
Correct |
3 ms |
4696 KB |
Output is correct |
59 |
Correct |
3 ms |
4700 KB |
Output is correct |
60 |
Correct |
2 ms |
4700 KB |
Output is correct |
61 |
Correct |
5 ms |
4788 KB |
Output is correct |
62 |
Correct |
3 ms |
4696 KB |
Output is correct |
63 |
Correct |
3 ms |
4700 KB |
Output is correct |
64 |
Correct |
3 ms |
4700 KB |
Output is correct |
65 |
Correct |
2 ms |
4700 KB |
Output is correct |
66 |
Correct |
2 ms |
4700 KB |
Output is correct |
67 |
Correct |
4 ms |
4544 KB |
Output is correct |
68 |
Correct |
3 ms |
4760 KB |
Output is correct |
69 |
Correct |
2 ms |
4700 KB |
Output is correct |
70 |
Correct |
3 ms |
4548 KB |
Output is correct |
71 |
Correct |
204 ms |
23364 KB |
Output is correct |
72 |
Correct |
217 ms |
23636 KB |
Output is correct |
73 |
Correct |
227 ms |
26056 KB |
Output is correct |
74 |
Correct |
265 ms |
26192 KB |
Output is correct |
75 |
Correct |
261 ms |
26680 KB |
Output is correct |
76 |
Correct |
256 ms |
26956 KB |
Output is correct |
77 |
Correct |
269 ms |
26192 KB |
Output is correct |
78 |
Correct |
278 ms |
26708 KB |
Output is correct |
79 |
Correct |
291 ms |
26960 KB |
Output is correct |
80 |
Correct |
400 ms |
25364 KB |
Output is correct |
81 |
Correct |
419 ms |
25572 KB |
Output is correct |
82 |
Correct |
451 ms |
26064 KB |
Output is correct |
83 |
Correct |
241 ms |
25428 KB |
Output is correct |
84 |
Correct |
154 ms |
25400 KB |
Output is correct |
85 |
Correct |
152 ms |
25420 KB |
Output is correct |
86 |
Correct |
335 ms |
26968 KB |
Output is correct |
87 |
Correct |
219 ms |
23896 KB |
Output is correct |
88 |
Correct |
141 ms |
23900 KB |
Output is correct |
89 |
Correct |
180 ms |
24020 KB |
Output is correct |
90 |
Correct |
165 ms |
23896 KB |
Output is correct |
91 |
Correct |
183 ms |
24028 KB |
Output is correct |
92 |
Correct |
167 ms |
24024 KB |
Output is correct |
93 |
Correct |
208 ms |
23900 KB |
Output is correct |
94 |
Correct |
163 ms |
24008 KB |
Output is correct |
95 |
Correct |
234 ms |
23896 KB |
Output is correct |
96 |
Execution timed out |
4069 ms |
23380 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |