#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 42;
int last = 0, nb;
bool inHand[N];
vector<int> first, second, id;
int send(int i) {
if(!inHand[i]) {
inHand[i] = true;
last = Query(id[i]);
}
return last;
}
int getBack(int i) {
if(inHand[i]) {
inHand[i] = false;
last = Query(id[i]);
}
return last;
}
int flip(int i) {
inHand[i] = !inHand[i];
last = Query(id[i]);
return last;
}
void print() {/*
for(int i = 0; i < 2*nb; i++)
cout << inHand[i];
cout << ' ' << last << '\n';*/
}
void DPR(vector<int> fi, vector<int> se) {
if((int)fi.size() == 1 && (int)se.size() == 1) {
Answer(id[fi[0]], id[se[0]]);
return;
}
if(fi.empty() || se.empty()) {
//cout << "wtf\n";
return;
}
int diff = 0;
vector<int> fi1, fi2, se1, se2;
for(int i = 0; i < (int)fi.size(); i++)
if(inHand[fi[i]])
diff++;
else
diff--;
for(int i = 0; i < (int)fi.size(); i++) {
if(inHand[fi[i]]) {
if(abs(diff) <= abs(diff - 2)) {
fi1.push_back(fi[i]);
} else {
diff -= 2;
getBack(fi[i]);
fi2.push_back(fi[i]);
}
} else {
if(abs(diff) > abs(diff + 2)) {
diff += 2;
send(fi[i]);
fi1.push_back(fi[i]);
} else {
fi2.push_back(fi[i]);
}
}
}
for(int j : se) {
int nbType = last;
if(se1.size() == fi1.size()) {
se2.push_back(j);
} else if(se2.size() == fi2.size()) {
se1.push_back(j);
} else if(flip(j) == nbType) {
se1.push_back(j);
} else {
se2.push_back(j);
}
}
fi.clear();
se.clear();
DPR(se1, fi1);
DPR(se2, fi2);
}
void Solve(int n) {
nb = n;
int nbType = 0;
mt19937 rng(43);
for(int i = 1; i <= 2*n; i++)
id.push_back(i);
shuffle(id.begin(), id.end(), rng);
for(int i = 0; i < 2*n; i++) {
if(send(i) == nbType) {
second.push_back(i);
} else {
nbType++;
first.push_back(i);
}
}
DPR(first, second);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
9 ms |
848 KB |
Output is correct |
5 |
Correct |
14 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
15 |
Correct |
42 ms |
3536 KB |
Output is correct |
16 |
Correct |
43 ms |
3520 KB |
Output is correct |
17 |
Correct |
39 ms |
3520 KB |
Output is correct |
18 |
Correct |
36 ms |
3452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
15 |
Correct |
42 ms |
3536 KB |
Output is correct |
16 |
Correct |
43 ms |
3520 KB |
Output is correct |
17 |
Correct |
39 ms |
3520 KB |
Output is correct |
18 |
Correct |
36 ms |
3452 KB |
Output is correct |
19 |
Correct |
39 ms |
3596 KB |
Output is correct |
20 |
Correct |
37 ms |
3656 KB |
Output is correct |
21 |
Correct |
39 ms |
3616 KB |
Output is correct |
22 |
Correct |
38 ms |
3508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
15 |
Correct |
42 ms |
3536 KB |
Output is correct |
16 |
Correct |
43 ms |
3520 KB |
Output is correct |
17 |
Correct |
39 ms |
3520 KB |
Output is correct |
18 |
Correct |
36 ms |
3452 KB |
Output is correct |
19 |
Correct |
39 ms |
3596 KB |
Output is correct |
20 |
Correct |
37 ms |
3656 KB |
Output is correct |
21 |
Correct |
39 ms |
3616 KB |
Output is correct |
22 |
Correct |
38 ms |
3508 KB |
Output is correct |
23 |
Correct |
49 ms |
3656 KB |
Output is correct |
24 |
Correct |
38 ms |
3656 KB |
Output is correct |
25 |
Correct |
37 ms |
3656 KB |
Output is correct |
26 |
Correct |
43 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
15 |
Correct |
42 ms |
3536 KB |
Output is correct |
16 |
Correct |
43 ms |
3520 KB |
Output is correct |
17 |
Correct |
39 ms |
3520 KB |
Output is correct |
18 |
Correct |
36 ms |
3452 KB |
Output is correct |
19 |
Correct |
39 ms |
3596 KB |
Output is correct |
20 |
Correct |
37 ms |
3656 KB |
Output is correct |
21 |
Correct |
39 ms |
3616 KB |
Output is correct |
22 |
Correct |
38 ms |
3508 KB |
Output is correct |
23 |
Correct |
49 ms |
3656 KB |
Output is correct |
24 |
Correct |
38 ms |
3656 KB |
Output is correct |
25 |
Correct |
37 ms |
3656 KB |
Output is correct |
26 |
Correct |
43 ms |
3564 KB |
Output is correct |
27 |
Correct |
39 ms |
3800 KB |
Output is correct |
28 |
Correct |
40 ms |
3684 KB |
Output is correct |
29 |
Correct |
43 ms |
3768 KB |
Output is correct |
30 |
Correct |
47 ms |
3616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
15 |
Correct |
42 ms |
3536 KB |
Output is correct |
16 |
Correct |
43 ms |
3520 KB |
Output is correct |
17 |
Correct |
39 ms |
3520 KB |
Output is correct |
18 |
Correct |
36 ms |
3452 KB |
Output is correct |
19 |
Correct |
39 ms |
3596 KB |
Output is correct |
20 |
Correct |
37 ms |
3656 KB |
Output is correct |
21 |
Correct |
39 ms |
3616 KB |
Output is correct |
22 |
Correct |
38 ms |
3508 KB |
Output is correct |
23 |
Correct |
49 ms |
3656 KB |
Output is correct |
24 |
Correct |
38 ms |
3656 KB |
Output is correct |
25 |
Correct |
37 ms |
3656 KB |
Output is correct |
26 |
Correct |
43 ms |
3564 KB |
Output is correct |
27 |
Correct |
39 ms |
3800 KB |
Output is correct |
28 |
Correct |
40 ms |
3684 KB |
Output is correct |
29 |
Correct |
43 ms |
3768 KB |
Output is correct |
30 |
Correct |
47 ms |
3616 KB |
Output is correct |
31 |
Correct |
40 ms |
3860 KB |
Output is correct |
32 |
Correct |
43 ms |
3760 KB |
Output is correct |
33 |
Correct |
40 ms |
3788 KB |
Output is correct |
34 |
Correct |
50 ms |
3708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
848 KB |
Output is correct |
9 |
Correct |
14 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1236 KB |
Output is correct |
12 |
Correct |
13 ms |
1488 KB |
Output is correct |
13 |
Correct |
18 ms |
1488 KB |
Output is correct |
14 |
Correct |
13 ms |
1500 KB |
Output is correct |
15 |
Correct |
42 ms |
3536 KB |
Output is correct |
16 |
Correct |
43 ms |
3520 KB |
Output is correct |
17 |
Correct |
39 ms |
3520 KB |
Output is correct |
18 |
Correct |
36 ms |
3452 KB |
Output is correct |
19 |
Correct |
39 ms |
3596 KB |
Output is correct |
20 |
Correct |
37 ms |
3656 KB |
Output is correct |
21 |
Correct |
39 ms |
3616 KB |
Output is correct |
22 |
Correct |
38 ms |
3508 KB |
Output is correct |
23 |
Correct |
49 ms |
3656 KB |
Output is correct |
24 |
Correct |
38 ms |
3656 KB |
Output is correct |
25 |
Correct |
37 ms |
3656 KB |
Output is correct |
26 |
Correct |
43 ms |
3564 KB |
Output is correct |
27 |
Correct |
39 ms |
3800 KB |
Output is correct |
28 |
Correct |
40 ms |
3684 KB |
Output is correct |
29 |
Correct |
43 ms |
3768 KB |
Output is correct |
30 |
Correct |
47 ms |
3616 KB |
Output is correct |
31 |
Correct |
40 ms |
3860 KB |
Output is correct |
32 |
Correct |
43 ms |
3760 KB |
Output is correct |
33 |
Correct |
40 ms |
3788 KB |
Output is correct |
34 |
Correct |
50 ms |
3708 KB |
Output is correct |
35 |
Correct |
41 ms |
3832 KB |
Output is correct |
36 |
Correct |
47 ms |
3936 KB |
Output is correct |
37 |
Correct |
40 ms |
3900 KB |
Output is correct |
38 |
Correct |
39 ms |
3776 KB |
Output is correct |