#include <bits/stdc++.h>
#include "minerals.h"
using namespace std;
vector<int> Q;
vector<int> P;
int ans[86005];
int ON[86005];
int last;
int verdict;
int query(int x){
ON[x] ^= 1;
verdict = ON[x];
return Query(x);
}
void solve(vector<int> p, vector<int> q){
if (p.size() == 1){
Answer(q[0],p[0]);
return;
}
else if (p.size() == 2){
//printf("settle <%d,%d> <-> <%d,%d>\n",q[0],q[1],p[0],p[1]);
//printf("last query %d\n",last);
int q1;
int qon, qoff, On, Off;
if (ON[q[0]]^ON[q[1]]) {
qon = ON[q[0]]?q[0]:q[1];
qoff = ON[q[0]]?q[1]:q[0];
q1 = -1;
}
else{
q1 = query(q[0]);
qon = ON[q[0]]?q[0]:q[1];
qoff = ON[q[0]]?q[1]:q[0];
}
assert(ON[qon] && !ON[qoff]);
if (ON[p[0]] ^ ON[p[1]]){
On = ON[p[0]]?p[0]:p[1];
Off = ON[p[0]]?p[1]:p[0];
if (q1 == -1){
q1 = query(On);
if (q1 == last){
Answer(qon, On);
Answer(qoff, Off);
}
}
else if (q1 == last){
Answer(q[0],On);
Answer(q[1],Off);
}
else{
Answer(q[0],Off);
Answer(q[1],On);
}
last = q1;
return;
}
if (q1 == -1){
q1 = query(p[0]);
On = ON[p[0]]?p[0]:p[1];
Off = ON[p[0]]?p[1]:p[0];
if ((verdict == 0) ^ (q1 == last)){
Answer(qon,On);
Answer(qoff,Off);
}
else{
Answer(qoff,On);
Answer(qon,Off);
}
last = q1;
return;
}
else last = q1;
q1 = query(p[0]);
On = ON[p[0]]?p[0]:p[1];
Off = ON[p[0]]?p[1]:p[0];
if ((verdict == 0) ^ (q1 == last)){
Answer(qon,On);
Answer(qoff,Off);
}
else{
Answer(qoff,On);
Answer(qon,Off);
}
last = q1;
return;
}
#ifdef debug
for (auto x : p){
printf("%d ",x);
}
printf("<- P\n");
for (auto x : q){
printf("%d ",x);
}
printf("<- P\n");
#endif
assert(p.size() == q.size());
vector<int> Lp;
vector<int> Rp;
vector<int> Lq, Rq;
int n = q.size();
int mid = n/2;
for (auto x : q){
if (ON[x]){
if (Lq.size() == mid){
last = query(x);
Rq.push_back(x);
}
else{
Lq.push_back(x);
}
}
else{
if (Rq.size() == q.size()-mid){
last = query(x);
Lq.push_back(x);
}
else{
Rq.push_back(x);
}
}
}
for (int i = 0; i < n; i++){
int q = query(p[i]);
if (q == last){
//printf("%d goes left\n",p[i]);
Lp.push_back(p[i]);
}
else{
//printf("%d goes right\n",p[i]);
Rp.push_back(p[i]);
}
last = q;
if (Lp.size() == Lq.size() || Rp.size() == Rq.size()){
//printf("ALL FILLED\n");
for (int j = i+1; j < n; j++){
if (Lp.size() == Lq.size()) Rp.push_back(p[j]);
else Lp.push_back(p[j]);
}
break;
}
}
#ifdef debug
printf("Lp: ");
for (auto x : Lp) printf("%d ",x);
printf("\n");
printf("Rp: ");
for (auto x : Rp) printf("%d ",x);
printf("\n");
#endif
solve(Lp, Lq);
solve(Rp, Rq);
}
void Solve(int N) {
for (int i = 1; i <= 2*N; i++){
int q = query(i);
if (q == last){
Q.push_back(i);
}
else{
P.push_back(i);
}
last = q;
ON[i] = 1;
}
//srand(time(NULL));
//random_shuffle(Q.begin(),Q.end());
//random_shuffle(P.begin(),P.end());
solve(P,Q);
}
Compilation message
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>)':
minerals.cpp:105:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (Lq.size() == mid){
~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
9 ms |
896 KB |
Output is correct |
5 |
Correct |
19 ms |
1588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
15 |
Correct |
54 ms |
3504 KB |
Output is correct |
16 |
Correct |
53 ms |
3576 KB |
Output is correct |
17 |
Correct |
42 ms |
3468 KB |
Output is correct |
18 |
Correct |
43 ms |
3332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
15 |
Correct |
54 ms |
3504 KB |
Output is correct |
16 |
Correct |
53 ms |
3576 KB |
Output is correct |
17 |
Correct |
42 ms |
3468 KB |
Output is correct |
18 |
Correct |
43 ms |
3332 KB |
Output is correct |
19 |
Correct |
55 ms |
3644 KB |
Output is correct |
20 |
Correct |
57 ms |
3616 KB |
Output is correct |
21 |
Correct |
42 ms |
3552 KB |
Output is correct |
22 |
Correct |
43 ms |
3388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
15 |
Correct |
54 ms |
3504 KB |
Output is correct |
16 |
Correct |
53 ms |
3576 KB |
Output is correct |
17 |
Correct |
42 ms |
3468 KB |
Output is correct |
18 |
Correct |
43 ms |
3332 KB |
Output is correct |
19 |
Correct |
55 ms |
3644 KB |
Output is correct |
20 |
Correct |
57 ms |
3616 KB |
Output is correct |
21 |
Correct |
42 ms |
3552 KB |
Output is correct |
22 |
Correct |
43 ms |
3388 KB |
Output is correct |
23 |
Correct |
56 ms |
3664 KB |
Output is correct |
24 |
Correct |
58 ms |
3672 KB |
Output is correct |
25 |
Correct |
44 ms |
3600 KB |
Output is correct |
26 |
Correct |
45 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
15 |
Correct |
54 ms |
3504 KB |
Output is correct |
16 |
Correct |
53 ms |
3576 KB |
Output is correct |
17 |
Correct |
42 ms |
3468 KB |
Output is correct |
18 |
Correct |
43 ms |
3332 KB |
Output is correct |
19 |
Correct |
55 ms |
3644 KB |
Output is correct |
20 |
Correct |
57 ms |
3616 KB |
Output is correct |
21 |
Correct |
42 ms |
3552 KB |
Output is correct |
22 |
Correct |
43 ms |
3388 KB |
Output is correct |
23 |
Correct |
56 ms |
3664 KB |
Output is correct |
24 |
Correct |
58 ms |
3672 KB |
Output is correct |
25 |
Correct |
44 ms |
3600 KB |
Output is correct |
26 |
Correct |
45 ms |
3456 KB |
Output is correct |
27 |
Correct |
58 ms |
3732 KB |
Output is correct |
28 |
Correct |
61 ms |
3768 KB |
Output is correct |
29 |
Correct |
47 ms |
3700 KB |
Output is correct |
30 |
Correct |
53 ms |
3536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
15 |
Correct |
54 ms |
3504 KB |
Output is correct |
16 |
Correct |
53 ms |
3576 KB |
Output is correct |
17 |
Correct |
42 ms |
3468 KB |
Output is correct |
18 |
Correct |
43 ms |
3332 KB |
Output is correct |
19 |
Correct |
55 ms |
3644 KB |
Output is correct |
20 |
Correct |
57 ms |
3616 KB |
Output is correct |
21 |
Correct |
42 ms |
3552 KB |
Output is correct |
22 |
Correct |
43 ms |
3388 KB |
Output is correct |
23 |
Correct |
56 ms |
3664 KB |
Output is correct |
24 |
Correct |
58 ms |
3672 KB |
Output is correct |
25 |
Correct |
44 ms |
3600 KB |
Output is correct |
26 |
Correct |
45 ms |
3456 KB |
Output is correct |
27 |
Correct |
58 ms |
3732 KB |
Output is correct |
28 |
Correct |
61 ms |
3768 KB |
Output is correct |
29 |
Correct |
47 ms |
3700 KB |
Output is correct |
30 |
Correct |
53 ms |
3536 KB |
Output is correct |
31 |
Correct |
66 ms |
3780 KB |
Output is correct |
32 |
Correct |
60 ms |
3816 KB |
Output is correct |
33 |
Correct |
52 ms |
3700 KB |
Output is correct |
34 |
Correct |
47 ms |
3572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
19 ms |
1588 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1244 KB |
Output is correct |
12 |
Correct |
19 ms |
1580 KB |
Output is correct |
13 |
Correct |
15 ms |
1588 KB |
Output is correct |
14 |
Correct |
15 ms |
1452 KB |
Output is correct |
15 |
Correct |
54 ms |
3504 KB |
Output is correct |
16 |
Correct |
53 ms |
3576 KB |
Output is correct |
17 |
Correct |
42 ms |
3468 KB |
Output is correct |
18 |
Correct |
43 ms |
3332 KB |
Output is correct |
19 |
Correct |
55 ms |
3644 KB |
Output is correct |
20 |
Correct |
57 ms |
3616 KB |
Output is correct |
21 |
Correct |
42 ms |
3552 KB |
Output is correct |
22 |
Correct |
43 ms |
3388 KB |
Output is correct |
23 |
Correct |
56 ms |
3664 KB |
Output is correct |
24 |
Correct |
58 ms |
3672 KB |
Output is correct |
25 |
Correct |
44 ms |
3600 KB |
Output is correct |
26 |
Correct |
45 ms |
3456 KB |
Output is correct |
27 |
Correct |
58 ms |
3732 KB |
Output is correct |
28 |
Correct |
61 ms |
3768 KB |
Output is correct |
29 |
Correct |
47 ms |
3700 KB |
Output is correct |
30 |
Correct |
53 ms |
3536 KB |
Output is correct |
31 |
Correct |
66 ms |
3780 KB |
Output is correct |
32 |
Correct |
60 ms |
3816 KB |
Output is correct |
33 |
Correct |
52 ms |
3700 KB |
Output is correct |
34 |
Correct |
47 ms |
3572 KB |
Output is correct |
35 |
Incorrect |
67 ms |
3836 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |