#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, cur, ans[100100], chk[100100];
int dp[100100], opt[100100];
void dnc0(vector<int> a);
void dnc1(vector<int> L, vector<int> R, int onL, int onR);
int myquery(int x){
chk[x] ^= 1;
cur = Query(x);
return cur;
}
void dnc0(vector<int> a){
int c = a.size() / 2;
if (c==0) return;
if (c==1){
ans[a[0]] = a[1];
ans[a[1]] = a[0];
return;
}
vector<int> L, R;
for (auto &x:a){
int prv = cur;
int now = myquery(x);
if (now==prv){
R.push_back(x);
}
else{
L.push_back(x);
}
}
dnc1(L, R, 1, 1);
}
void dnc1(vector<int> L, vector<int> R, int onL, int onR){
// printf("dnc1: ");
// for (auto &x:L) printf("%d ", x);
// printf("\n");
// for (auto &x:R) printf("%d ", x);
// printf("\n");
int c = L.size();
if (c==0) return;
if (c==1){
ans[L[0]] = R[0];
ans[R[0]] = L[0];
return;
}
vector<int> L1, R1, L2, R2;
for (int i=0;i<opt[c];i++) {L1.push_back(L[i]); myquery(L[i]);}
for (int i=opt[c];i<c;i++) L2.push_back(L[i]);
for (auto &x:R){
if (x==R.back()){
if (L1.size()!=R1.size()) R1.push_back(x);
else R2.push_back(x);
break;
}
int prv = cur;
int delta = myquery(x) - prv;
if ((!onL) == (delta==0)) R1.push_back(x);
else R2.push_back(x);
}
dnc1(L1, R1, !onL, !onR);
dnc1(L2, R2, onL, !onR);
}
void run(int MX){
dp[0] = 0;
dp[1] = 0;
for (int i=2;i<=MX;i++){
dp[i] = 1e9;
opt[i] = -1;
int s = 0.27 * i;
int e = 0.383 * i;
if (i<=100) s = 1, e = i-1;
for (int j=s;j<=e;j++){
int val = j + (i-1) + dp[j] + dp[i-j];
if (val < dp[i]) dp[i] = val, opt[i] = j;
}
}
}
void Solve(int N) {
run(43000);
n = N, cur = 0;
vector<int> a;
for (int i=1;i<=n*2;i++) a.push_back(i);
dnc0(a);
for (int i=1;i<=n*2;i++) if (i < ans[i]) Answer(i, ans[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
704 KB |
Output is correct |
2 |
Correct |
91 ms |
840 KB |
Output is correct |
3 |
Correct |
95 ms |
1080 KB |
Output is correct |
4 |
Correct |
97 ms |
1632 KB |
Output is correct |
5 |
Correct |
108 ms |
2508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
15 |
Correct |
125 ms |
4912 KB |
Output is correct |
16 |
Correct |
127 ms |
5072 KB |
Output is correct |
17 |
Correct |
119 ms |
4996 KB |
Output is correct |
18 |
Correct |
124 ms |
4960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
15 |
Correct |
125 ms |
4912 KB |
Output is correct |
16 |
Correct |
127 ms |
5072 KB |
Output is correct |
17 |
Correct |
119 ms |
4996 KB |
Output is correct |
18 |
Correct |
124 ms |
4960 KB |
Output is correct |
19 |
Correct |
129 ms |
5104 KB |
Output is correct |
20 |
Correct |
134 ms |
5088 KB |
Output is correct |
21 |
Correct |
127 ms |
5036 KB |
Output is correct |
22 |
Correct |
126 ms |
4896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
15 |
Correct |
125 ms |
4912 KB |
Output is correct |
16 |
Correct |
127 ms |
5072 KB |
Output is correct |
17 |
Correct |
119 ms |
4996 KB |
Output is correct |
18 |
Correct |
124 ms |
4960 KB |
Output is correct |
19 |
Correct |
129 ms |
5104 KB |
Output is correct |
20 |
Correct |
134 ms |
5088 KB |
Output is correct |
21 |
Correct |
127 ms |
5036 KB |
Output is correct |
22 |
Correct |
126 ms |
4896 KB |
Output is correct |
23 |
Correct |
129 ms |
5300 KB |
Output is correct |
24 |
Correct |
174 ms |
5168 KB |
Output is correct |
25 |
Correct |
129 ms |
5100 KB |
Output is correct |
26 |
Correct |
126 ms |
5056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
15 |
Correct |
125 ms |
4912 KB |
Output is correct |
16 |
Correct |
127 ms |
5072 KB |
Output is correct |
17 |
Correct |
119 ms |
4996 KB |
Output is correct |
18 |
Correct |
124 ms |
4960 KB |
Output is correct |
19 |
Correct |
129 ms |
5104 KB |
Output is correct |
20 |
Correct |
134 ms |
5088 KB |
Output is correct |
21 |
Correct |
127 ms |
5036 KB |
Output is correct |
22 |
Correct |
126 ms |
4896 KB |
Output is correct |
23 |
Correct |
129 ms |
5300 KB |
Output is correct |
24 |
Correct |
174 ms |
5168 KB |
Output is correct |
25 |
Correct |
129 ms |
5100 KB |
Output is correct |
26 |
Correct |
126 ms |
5056 KB |
Output is correct |
27 |
Correct |
136 ms |
5244 KB |
Output is correct |
28 |
Correct |
137 ms |
5284 KB |
Output is correct |
29 |
Correct |
122 ms |
5228 KB |
Output is correct |
30 |
Correct |
124 ms |
5104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
15 |
Correct |
125 ms |
4912 KB |
Output is correct |
16 |
Correct |
127 ms |
5072 KB |
Output is correct |
17 |
Correct |
119 ms |
4996 KB |
Output is correct |
18 |
Correct |
124 ms |
4960 KB |
Output is correct |
19 |
Correct |
129 ms |
5104 KB |
Output is correct |
20 |
Correct |
134 ms |
5088 KB |
Output is correct |
21 |
Correct |
127 ms |
5036 KB |
Output is correct |
22 |
Correct |
126 ms |
4896 KB |
Output is correct |
23 |
Correct |
129 ms |
5300 KB |
Output is correct |
24 |
Correct |
174 ms |
5168 KB |
Output is correct |
25 |
Correct |
129 ms |
5100 KB |
Output is correct |
26 |
Correct |
126 ms |
5056 KB |
Output is correct |
27 |
Correct |
136 ms |
5244 KB |
Output is correct |
28 |
Correct |
137 ms |
5284 KB |
Output is correct |
29 |
Correct |
122 ms |
5228 KB |
Output is correct |
30 |
Correct |
124 ms |
5104 KB |
Output is correct |
31 |
Correct |
129 ms |
5340 KB |
Output is correct |
32 |
Correct |
154 ms |
5296 KB |
Output is correct |
33 |
Correct |
125 ms |
5304 KB |
Output is correct |
34 |
Correct |
128 ms |
5236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
616 KB |
Output is correct |
2 |
Correct |
95 ms |
676 KB |
Output is correct |
3 |
Correct |
87 ms |
608 KB |
Output is correct |
4 |
Correct |
89 ms |
624 KB |
Output is correct |
5 |
Correct |
90 ms |
704 KB |
Output is correct |
6 |
Correct |
91 ms |
840 KB |
Output is correct |
7 |
Correct |
95 ms |
1080 KB |
Output is correct |
8 |
Correct |
97 ms |
1632 KB |
Output is correct |
9 |
Correct |
108 ms |
2508 KB |
Output is correct |
10 |
Correct |
89 ms |
748 KB |
Output is correct |
11 |
Correct |
98 ms |
1748 KB |
Output is correct |
12 |
Correct |
112 ms |
2384 KB |
Output is correct |
13 |
Correct |
104 ms |
2508 KB |
Output is correct |
14 |
Correct |
108 ms |
2332 KB |
Output is correct |
15 |
Correct |
125 ms |
4912 KB |
Output is correct |
16 |
Correct |
127 ms |
5072 KB |
Output is correct |
17 |
Correct |
119 ms |
4996 KB |
Output is correct |
18 |
Correct |
124 ms |
4960 KB |
Output is correct |
19 |
Correct |
129 ms |
5104 KB |
Output is correct |
20 |
Correct |
134 ms |
5088 KB |
Output is correct |
21 |
Correct |
127 ms |
5036 KB |
Output is correct |
22 |
Correct |
126 ms |
4896 KB |
Output is correct |
23 |
Correct |
129 ms |
5300 KB |
Output is correct |
24 |
Correct |
174 ms |
5168 KB |
Output is correct |
25 |
Correct |
129 ms |
5100 KB |
Output is correct |
26 |
Correct |
126 ms |
5056 KB |
Output is correct |
27 |
Correct |
136 ms |
5244 KB |
Output is correct |
28 |
Correct |
137 ms |
5284 KB |
Output is correct |
29 |
Correct |
122 ms |
5228 KB |
Output is correct |
30 |
Correct |
124 ms |
5104 KB |
Output is correct |
31 |
Correct |
129 ms |
5340 KB |
Output is correct |
32 |
Correct |
154 ms |
5296 KB |
Output is correct |
33 |
Correct |
125 ms |
5304 KB |
Output is correct |
34 |
Correct |
128 ms |
5236 KB |
Output is correct |
35 |
Correct |
129 ms |
5556 KB |
Output is correct |
36 |
Correct |
140 ms |
5408 KB |
Output is correct |
37 |
Correct |
125 ms |
5440 KB |
Output is correct |
38 |
Correct |
127 ms |
5284 KB |
Output is correct |