#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:106:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (Lq.size() == mid){
~~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
11 ms |
1024 KB |
Output is correct |
5 |
Correct |
20 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
15 |
Correct |
60 ms |
3508 KB |
Output is correct |
16 |
Correct |
64 ms |
3640 KB |
Output is correct |
17 |
Correct |
58 ms |
3520 KB |
Output is correct |
18 |
Correct |
59 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
15 |
Correct |
60 ms |
3508 KB |
Output is correct |
16 |
Correct |
64 ms |
3640 KB |
Output is correct |
17 |
Correct |
58 ms |
3520 KB |
Output is correct |
18 |
Correct |
59 ms |
3412 KB |
Output is correct |
19 |
Correct |
62 ms |
3572 KB |
Output is correct |
20 |
Correct |
64 ms |
3588 KB |
Output is correct |
21 |
Correct |
59 ms |
3704 KB |
Output is correct |
22 |
Correct |
60 ms |
3444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
15 |
Correct |
60 ms |
3508 KB |
Output is correct |
16 |
Correct |
64 ms |
3640 KB |
Output is correct |
17 |
Correct |
58 ms |
3520 KB |
Output is correct |
18 |
Correct |
59 ms |
3412 KB |
Output is correct |
19 |
Correct |
62 ms |
3572 KB |
Output is correct |
20 |
Correct |
64 ms |
3588 KB |
Output is correct |
21 |
Correct |
59 ms |
3704 KB |
Output is correct |
22 |
Correct |
60 ms |
3444 KB |
Output is correct |
23 |
Correct |
66 ms |
3708 KB |
Output is correct |
24 |
Correct |
72 ms |
3728 KB |
Output is correct |
25 |
Correct |
62 ms |
3700 KB |
Output is correct |
26 |
Correct |
63 ms |
3540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
15 |
Correct |
60 ms |
3508 KB |
Output is correct |
16 |
Correct |
64 ms |
3640 KB |
Output is correct |
17 |
Correct |
58 ms |
3520 KB |
Output is correct |
18 |
Correct |
59 ms |
3412 KB |
Output is correct |
19 |
Correct |
62 ms |
3572 KB |
Output is correct |
20 |
Correct |
64 ms |
3588 KB |
Output is correct |
21 |
Correct |
59 ms |
3704 KB |
Output is correct |
22 |
Correct |
60 ms |
3444 KB |
Output is correct |
23 |
Correct |
66 ms |
3708 KB |
Output is correct |
24 |
Correct |
72 ms |
3728 KB |
Output is correct |
25 |
Correct |
62 ms |
3700 KB |
Output is correct |
26 |
Correct |
63 ms |
3540 KB |
Output is correct |
27 |
Correct |
66 ms |
3700 KB |
Output is correct |
28 |
Correct |
65 ms |
3868 KB |
Output is correct |
29 |
Correct |
62 ms |
3748 KB |
Output is correct |
30 |
Correct |
66 ms |
3572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
15 |
Correct |
60 ms |
3508 KB |
Output is correct |
16 |
Correct |
64 ms |
3640 KB |
Output is correct |
17 |
Correct |
58 ms |
3520 KB |
Output is correct |
18 |
Correct |
59 ms |
3412 KB |
Output is correct |
19 |
Correct |
62 ms |
3572 KB |
Output is correct |
20 |
Correct |
64 ms |
3588 KB |
Output is correct |
21 |
Correct |
59 ms |
3704 KB |
Output is correct |
22 |
Correct |
60 ms |
3444 KB |
Output is correct |
23 |
Correct |
66 ms |
3708 KB |
Output is correct |
24 |
Correct |
72 ms |
3728 KB |
Output is correct |
25 |
Correct |
62 ms |
3700 KB |
Output is correct |
26 |
Correct |
63 ms |
3540 KB |
Output is correct |
27 |
Correct |
66 ms |
3700 KB |
Output is correct |
28 |
Correct |
65 ms |
3868 KB |
Output is correct |
29 |
Correct |
62 ms |
3748 KB |
Output is correct |
30 |
Correct |
66 ms |
3572 KB |
Output is correct |
31 |
Correct |
68 ms |
3828 KB |
Output is correct |
32 |
Correct |
68 ms |
3836 KB |
Output is correct |
33 |
Correct |
67 ms |
3848 KB |
Output is correct |
34 |
Correct |
64 ms |
3660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1152 KB |
Output is correct |
12 |
Correct |
21 ms |
1536 KB |
Output is correct |
13 |
Correct |
23 ms |
1596 KB |
Output is correct |
14 |
Correct |
20 ms |
1536 KB |
Output is correct |
15 |
Correct |
60 ms |
3508 KB |
Output is correct |
16 |
Correct |
64 ms |
3640 KB |
Output is correct |
17 |
Correct |
58 ms |
3520 KB |
Output is correct |
18 |
Correct |
59 ms |
3412 KB |
Output is correct |
19 |
Correct |
62 ms |
3572 KB |
Output is correct |
20 |
Correct |
64 ms |
3588 KB |
Output is correct |
21 |
Correct |
59 ms |
3704 KB |
Output is correct |
22 |
Correct |
60 ms |
3444 KB |
Output is correct |
23 |
Correct |
66 ms |
3708 KB |
Output is correct |
24 |
Correct |
72 ms |
3728 KB |
Output is correct |
25 |
Correct |
62 ms |
3700 KB |
Output is correct |
26 |
Correct |
63 ms |
3540 KB |
Output is correct |
27 |
Correct |
66 ms |
3700 KB |
Output is correct |
28 |
Correct |
65 ms |
3868 KB |
Output is correct |
29 |
Correct |
62 ms |
3748 KB |
Output is correct |
30 |
Correct |
66 ms |
3572 KB |
Output is correct |
31 |
Correct |
68 ms |
3828 KB |
Output is correct |
32 |
Correct |
68 ms |
3836 KB |
Output is correct |
33 |
Correct |
67 ms |
3848 KB |
Output is correct |
34 |
Correct |
64 ms |
3660 KB |
Output is correct |
35 |
Incorrect |
75 ms |
3888 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |