#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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
5 |
Correct |
16 ms |
1456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
15 |
Correct |
43 ms |
3544 KB |
Output is correct |
16 |
Correct |
35 ms |
3528 KB |
Output is correct |
17 |
Correct |
38 ms |
3592 KB |
Output is correct |
18 |
Correct |
36 ms |
3424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
15 |
Correct |
43 ms |
3544 KB |
Output is correct |
16 |
Correct |
35 ms |
3528 KB |
Output is correct |
17 |
Correct |
38 ms |
3592 KB |
Output is correct |
18 |
Correct |
36 ms |
3424 KB |
Output is correct |
19 |
Correct |
42 ms |
3648 KB |
Output is correct |
20 |
Correct |
37 ms |
3652 KB |
Output is correct |
21 |
Correct |
36 ms |
3616 KB |
Output is correct |
22 |
Correct |
35 ms |
3476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
15 |
Correct |
43 ms |
3544 KB |
Output is correct |
16 |
Correct |
35 ms |
3528 KB |
Output is correct |
17 |
Correct |
38 ms |
3592 KB |
Output is correct |
18 |
Correct |
36 ms |
3424 KB |
Output is correct |
19 |
Correct |
42 ms |
3648 KB |
Output is correct |
20 |
Correct |
37 ms |
3652 KB |
Output is correct |
21 |
Correct |
36 ms |
3616 KB |
Output is correct |
22 |
Correct |
35 ms |
3476 KB |
Output is correct |
23 |
Correct |
37 ms |
3748 KB |
Output is correct |
24 |
Correct |
41 ms |
3648 KB |
Output is correct |
25 |
Correct |
37 ms |
3704 KB |
Output is correct |
26 |
Correct |
37 ms |
3516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
15 |
Correct |
43 ms |
3544 KB |
Output is correct |
16 |
Correct |
35 ms |
3528 KB |
Output is correct |
17 |
Correct |
38 ms |
3592 KB |
Output is correct |
18 |
Correct |
36 ms |
3424 KB |
Output is correct |
19 |
Correct |
42 ms |
3648 KB |
Output is correct |
20 |
Correct |
37 ms |
3652 KB |
Output is correct |
21 |
Correct |
36 ms |
3616 KB |
Output is correct |
22 |
Correct |
35 ms |
3476 KB |
Output is correct |
23 |
Correct |
37 ms |
3748 KB |
Output is correct |
24 |
Correct |
41 ms |
3648 KB |
Output is correct |
25 |
Correct |
37 ms |
3704 KB |
Output is correct |
26 |
Correct |
37 ms |
3516 KB |
Output is correct |
27 |
Correct |
38 ms |
3800 KB |
Output is correct |
28 |
Correct |
39 ms |
3700 KB |
Output is correct |
29 |
Correct |
41 ms |
3772 KB |
Output is correct |
30 |
Correct |
37 ms |
3644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
15 |
Correct |
43 ms |
3544 KB |
Output is correct |
16 |
Correct |
35 ms |
3528 KB |
Output is correct |
17 |
Correct |
38 ms |
3592 KB |
Output is correct |
18 |
Correct |
36 ms |
3424 KB |
Output is correct |
19 |
Correct |
42 ms |
3648 KB |
Output is correct |
20 |
Correct |
37 ms |
3652 KB |
Output is correct |
21 |
Correct |
36 ms |
3616 KB |
Output is correct |
22 |
Correct |
35 ms |
3476 KB |
Output is correct |
23 |
Correct |
37 ms |
3748 KB |
Output is correct |
24 |
Correct |
41 ms |
3648 KB |
Output is correct |
25 |
Correct |
37 ms |
3704 KB |
Output is correct |
26 |
Correct |
37 ms |
3516 KB |
Output is correct |
27 |
Correct |
38 ms |
3800 KB |
Output is correct |
28 |
Correct |
39 ms |
3700 KB |
Output is correct |
29 |
Correct |
41 ms |
3772 KB |
Output is correct |
30 |
Correct |
37 ms |
3644 KB |
Output is correct |
31 |
Correct |
40 ms |
3912 KB |
Output is correct |
32 |
Correct |
39 ms |
3868 KB |
Output is correct |
33 |
Correct |
37 ms |
3916 KB |
Output is correct |
34 |
Correct |
40 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 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 |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
16 ms |
1456 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
12 ms |
1232 KB |
Output is correct |
12 |
Correct |
12 ms |
1588 KB |
Output is correct |
13 |
Correct |
12 ms |
1488 KB |
Output is correct |
14 |
Correct |
12 ms |
1420 KB |
Output is correct |
15 |
Correct |
43 ms |
3544 KB |
Output is correct |
16 |
Correct |
35 ms |
3528 KB |
Output is correct |
17 |
Correct |
38 ms |
3592 KB |
Output is correct |
18 |
Correct |
36 ms |
3424 KB |
Output is correct |
19 |
Correct |
42 ms |
3648 KB |
Output is correct |
20 |
Correct |
37 ms |
3652 KB |
Output is correct |
21 |
Correct |
36 ms |
3616 KB |
Output is correct |
22 |
Correct |
35 ms |
3476 KB |
Output is correct |
23 |
Correct |
37 ms |
3748 KB |
Output is correct |
24 |
Correct |
41 ms |
3648 KB |
Output is correct |
25 |
Correct |
37 ms |
3704 KB |
Output is correct |
26 |
Correct |
37 ms |
3516 KB |
Output is correct |
27 |
Correct |
38 ms |
3800 KB |
Output is correct |
28 |
Correct |
39 ms |
3700 KB |
Output is correct |
29 |
Correct |
41 ms |
3772 KB |
Output is correct |
30 |
Correct |
37 ms |
3644 KB |
Output is correct |
31 |
Correct |
40 ms |
3912 KB |
Output is correct |
32 |
Correct |
39 ms |
3868 KB |
Output is correct |
33 |
Correct |
37 ms |
3916 KB |
Output is correct |
34 |
Correct |
40 ms |
3692 KB |
Output is correct |
35 |
Correct |
45 ms |
3948 KB |
Output is correct |
36 |
Correct |
55 ms |
3904 KB |
Output is correct |
37 |
Correct |
43 ms |
3836 KB |
Output is correct |
38 |
Correct |
39 ms |
3784 KB |
Output is correct |