#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=22;
int N, M, A[Nmax], B[Nmax], D[Nmax][Nmax][Nmax][Nmax];
bool chk[Nmax][Nmax][Nmax][Nmax];
vector<int> Va, Vb;
bool F(int l, int r, int a, int b) {
if(l>r) return true;
if(l==r) return (a==A[l]) && (b==B[l]);
if(chk[l][r][a][b]) return D[l][r][a][b];
chk[l][r][a][b]=true;
for(int i=l; i<r; i++) {
bool flag1=false, flag2=false, flag3=false, flag4=false;
for(int y=b; y<=Vb.size(); y++) flag1|=F(l, i, a, y);
for(int x=a; x<=Va.size(); x++) flag2|=F(i+1, r, x, b);
for(int x=a; x<=Va.size(); x++) flag3|=F(l, i, x, b);
for(int y=b; y<=Vb.size(); y++) flag4|=F(i+1, r, a, y);
if(flag1 && flag2) return (D[l][r][a][b]=true);
if(flag3 && flag4) return (D[l][r][a][b]=true);
}
for(int i=l; i<r; i++) {
bool flag1=false, flag2=false, flag3=false, flag4=false;
flag1|=F(l, i, a, b);
for(int x=a; x<=Va.size(); x++) for(int y=b; y<=Vb.size(); y++) flag2|=F(i+1, r, x, y);
for(int x=a; x<=Va.size(); x++) for(int y=b; y<=Vb.size(); y++) flag3|=F(l, i, x, y);
flag4|=F(i+1, r, a, b);
if(flag1 && flag2) return (D[l][r][a][b]=true);
if(flag3 && flag4) return (D[l][r][a][b]=true);
}
for(int i=l; i<r; i++) {
bool flag1=false, flag2=false, flag3=false, flag4=false;
for(int y=1; y<=b; y++) flag1|=F(l, i, a, y);
for(int x=1; x<=a; x++) flag2|=F(i+1, r, x, b);
for(int x=1; x<=a; x++) flag3|=F(l, i, x, b);
for(int y=1; y<=b; y++) flag4|=F(i+1, r, a, y);
if(flag1 && flag2) return (D[l][r][a][b]=true);
if(flag3 && flag4) return (D[l][r][a][b]=true);
}
for(int i=l; i<r; i++) {
bool flag1=false, flag2=false, flag3=false, flag4=false;
flag1|=F(l, i, a, b);
for(int x=1; x<=a; x++) for(int y=1; y<=b; y++) flag2|=F(i+1, r, x, y);
for(int x=1; x<=a; x++) for(int y=1; y<=b; y++) flag3|=F(l, i, x, y);
flag4|=F(i+1, r, a, b);
if(flag1 && flag2) return (D[l][r][a][b]=true);
if(flag3 && flag4) return (D[l][r][a][b]=true);
}
return false;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>M;
for(int i=1; i<=N; i++) cin>>A[i]>>B[i], Va.push_back(A[i]), Vb.push_back(B[i]);
sort(Va.begin(), Va.end()), sort(Vb.begin(), Vb.end());
Va.erase(unique(Va.begin(), Va.end()), Va.end()), Vb.erase(unique(Vb.begin(), Vb.end()), Vb.end());
for(int i=1; i<=N; i++) A[i]=lower_bound(Va.begin(), Va.end(), A[i])-Va.begin()+1, B[i]=lower_bound(Vb.begin(), Vb.end(), B[i])-Vb.begin()+1;
for(int i=1; i<=M; i++) {
int a, b; cin>>a>>b;
auto p=lower_bound(Va.begin(), Va.end(), a);
if(p==Va.end() || (*p)!=a) continue;
a=p-Va.begin()+1;
auto q=lower_bound(Vb.begin(), Vb.end(), b);
if(q==Vb.end() || (*q)!=b) continue;
b=q-Vb.begin()+1;
if(F(1, N, a, b)) cout<<i<<" ";
}
return 0;
}
Compilation message
Main.cpp: In function 'bool F(long long int, long long int, long long int, long long int)':
Main.cpp:17:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int y=b; y<=Vb.size(); y++) flag1|=F(l, i, a, y);
| ~^~~~~~~~~~~
Main.cpp:18:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int x=a; x<=Va.size(); x++) flag2|=F(i+1, r, x, b);
| ~^~~~~~~~~~~
Main.cpp:19:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int x=a; x<=Va.size(); x++) flag3|=F(l, i, x, b);
| ~^~~~~~~~~~~
Main.cpp:20:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int y=b; y<=Vb.size(); y++) flag4|=F(i+1, r, a, y);
| ~^~~~~~~~~~~
Main.cpp:27:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int x=a; x<=Va.size(); x++) for(int y=b; y<=Vb.size(); y++) flag2|=F(i+1, r, x, y);
| ~^~~~~~~~~~~
Main.cpp:27:55: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int x=a; x<=Va.size(); x++) for(int y=b; y<=Vb.size(); y++) flag2|=F(i+1, r, x, y);
| ~^~~~~~~~~~~
Main.cpp:28:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int x=a; x<=Va.size(); x++) for(int y=b; y<=Vb.size(); y++) flag3|=F(l, i, x, y);
| ~^~~~~~~~~~~
Main.cpp:28:55: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int x=a; x<=Va.size(); x++) for(int y=b; y<=Vb.size(); y++) flag3|=F(l, i, x, y);
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
9 ms |
760 KB |
Output is correct |
12 |
Correct |
7 ms |
720 KB |
Output is correct |
13 |
Correct |
15 ms |
784 KB |
Output is correct |
14 |
Correct |
23 ms |
700 KB |
Output is correct |
15 |
Correct |
53 ms |
848 KB |
Output is correct |
16 |
Correct |
41 ms |
848 KB |
Output is correct |
17 |
Correct |
100 ms |
936 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
126 ms |
1312 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
122 ms |
880 KB |
Output is correct |
28 |
Correct |
182 ms |
848 KB |
Output is correct |
29 |
Correct |
272 ms |
892 KB |
Output is correct |
30 |
Correct |
394 ms |
1108 KB |
Output is correct |
31 |
Correct |
538 ms |
1112 KB |
Output is correct |
32 |
Correct |
823 ms |
1152 KB |
Output is correct |
33 |
Correct |
781 ms |
1428 KB |
Output is correct |
34 |
Correct |
970 ms |
1296 KB |
Output is correct |
35 |
Correct |
768 ms |
1144 KB |
Output is correct |
36 |
Correct |
15 ms |
1116 KB |
Output is correct |
37 |
Correct |
3 ms |
1236 KB |
Output is correct |
38 |
Correct |
3 ms |
1116 KB |
Output is correct |
39 |
Correct |
4 ms |
1116 KB |
Output is correct |
40 |
Correct |
4 ms |
1116 KB |
Output is correct |
41 |
Correct |
4 ms |
1112 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
4 ms |
1116 KB |
Output is correct |
44 |
Correct |
5 ms |
1356 KB |
Output is correct |
45 |
Correct |
10 ms |
1096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
9 ms |
760 KB |
Output is correct |
12 |
Correct |
7 ms |
720 KB |
Output is correct |
13 |
Correct |
15 ms |
784 KB |
Output is correct |
14 |
Correct |
23 ms |
700 KB |
Output is correct |
15 |
Correct |
53 ms |
848 KB |
Output is correct |
16 |
Correct |
41 ms |
848 KB |
Output is correct |
17 |
Correct |
100 ms |
936 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
126 ms |
1312 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
122 ms |
880 KB |
Output is correct |
28 |
Correct |
182 ms |
848 KB |
Output is correct |
29 |
Correct |
272 ms |
892 KB |
Output is correct |
30 |
Correct |
394 ms |
1108 KB |
Output is correct |
31 |
Correct |
538 ms |
1112 KB |
Output is correct |
32 |
Correct |
823 ms |
1152 KB |
Output is correct |
33 |
Correct |
781 ms |
1428 KB |
Output is correct |
34 |
Correct |
970 ms |
1296 KB |
Output is correct |
35 |
Correct |
768 ms |
1144 KB |
Output is correct |
36 |
Correct |
15 ms |
1116 KB |
Output is correct |
37 |
Correct |
3 ms |
1236 KB |
Output is correct |
38 |
Correct |
3 ms |
1116 KB |
Output is correct |
39 |
Correct |
4 ms |
1116 KB |
Output is correct |
40 |
Correct |
4 ms |
1116 KB |
Output is correct |
41 |
Correct |
4 ms |
1112 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
4 ms |
1116 KB |
Output is correct |
44 |
Correct |
5 ms |
1356 KB |
Output is correct |
45 |
Correct |
10 ms |
1096 KB |
Output is correct |
46 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
9 ms |
760 KB |
Output is correct |
12 |
Correct |
7 ms |
720 KB |
Output is correct |
13 |
Correct |
15 ms |
784 KB |
Output is correct |
14 |
Correct |
23 ms |
700 KB |
Output is correct |
15 |
Correct |
53 ms |
848 KB |
Output is correct |
16 |
Correct |
41 ms |
848 KB |
Output is correct |
17 |
Correct |
100 ms |
936 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
126 ms |
1312 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
122 ms |
880 KB |
Output is correct |
28 |
Correct |
182 ms |
848 KB |
Output is correct |
29 |
Correct |
272 ms |
892 KB |
Output is correct |
30 |
Correct |
394 ms |
1108 KB |
Output is correct |
31 |
Correct |
538 ms |
1112 KB |
Output is correct |
32 |
Correct |
823 ms |
1152 KB |
Output is correct |
33 |
Correct |
781 ms |
1428 KB |
Output is correct |
34 |
Correct |
970 ms |
1296 KB |
Output is correct |
35 |
Correct |
768 ms |
1144 KB |
Output is correct |
36 |
Correct |
15 ms |
1116 KB |
Output is correct |
37 |
Correct |
3 ms |
1236 KB |
Output is correct |
38 |
Correct |
3 ms |
1116 KB |
Output is correct |
39 |
Correct |
4 ms |
1116 KB |
Output is correct |
40 |
Correct |
4 ms |
1116 KB |
Output is correct |
41 |
Correct |
4 ms |
1112 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
4 ms |
1116 KB |
Output is correct |
44 |
Correct |
5 ms |
1356 KB |
Output is correct |
45 |
Correct |
10 ms |
1096 KB |
Output is correct |
46 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
9 ms |
760 KB |
Output is correct |
12 |
Correct |
7 ms |
720 KB |
Output is correct |
13 |
Correct |
15 ms |
784 KB |
Output is correct |
14 |
Correct |
23 ms |
700 KB |
Output is correct |
15 |
Correct |
53 ms |
848 KB |
Output is correct |
16 |
Correct |
41 ms |
848 KB |
Output is correct |
17 |
Correct |
100 ms |
936 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
126 ms |
1312 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
122 ms |
880 KB |
Output is correct |
28 |
Correct |
182 ms |
848 KB |
Output is correct |
29 |
Correct |
272 ms |
892 KB |
Output is correct |
30 |
Correct |
394 ms |
1108 KB |
Output is correct |
31 |
Correct |
538 ms |
1112 KB |
Output is correct |
32 |
Correct |
823 ms |
1152 KB |
Output is correct |
33 |
Correct |
781 ms |
1428 KB |
Output is correct |
34 |
Correct |
970 ms |
1296 KB |
Output is correct |
35 |
Correct |
768 ms |
1144 KB |
Output is correct |
36 |
Correct |
15 ms |
1116 KB |
Output is correct |
37 |
Correct |
3 ms |
1236 KB |
Output is correct |
38 |
Correct |
3 ms |
1116 KB |
Output is correct |
39 |
Correct |
4 ms |
1116 KB |
Output is correct |
40 |
Correct |
4 ms |
1116 KB |
Output is correct |
41 |
Correct |
4 ms |
1112 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
4 ms |
1116 KB |
Output is correct |
44 |
Correct |
5 ms |
1356 KB |
Output is correct |
45 |
Correct |
10 ms |
1096 KB |
Output is correct |
46 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
47 |
Halted |
0 ms |
0 KB |
- |