#include "minerals.h"
#include <bits/stdc++.h>
namespace {
using namespace std;
const int N = 43005;
int cost[N], best[N], cur = 0;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
void Prepare() {
cost[2] = 2; best[2] = 1;
for (int i = 3; i < N; i++) {
int j = best[i - 1];
if (cost[i - j - 1] + cost[j + 1] +
j + 1 < cost[i - j] + cost[j] + j) j++;
cost[i] = cost[i - j] + cost[j] + j + i;
best[i] = j;
}
}
void Split(vector<int> x, vector<int> y, bool f) {
if (x.size() == 2) {
cur = Query(x[f]);
int nxt = Query(y[0]);
if (cur != nxt) {
Answer(x[0], y[0]);
Answer(x[1], y[1]);
} else {
Answer(x[0], y[1]);
Answer(x[1], y[0]);
}
cur = nxt; return;
}
if (x.size() == 1)
return Answer(x[0], y[0]);
int n = x.size(), len = best[n];
vector<int> nx[2], ny[2];
for (int i = 0; i < len; i++) {
nx[f ^ 1].push_back(x[i]);
cur = Query(x[i]);
}
for (int i = len; i < n; i++)
nx[f].push_back(x[i]);
shuffle(y.begin(), y.end(), rng);
for (int i = 0; i < n; i++) {
if (nx[0].size() == ny[0].size()) {
ny[1].push_back(y[i]); continue;
}
int nxt = Query(y[i]);
if (cur != nxt)
ny[1].push_back(y[i]);
else ny[0].push_back(y[i]);
cur = nxt;
}
Split(nx[0], ny[0], 0);
Split(nx[1], ny[1], 1);
}
}
void Solve(int n) {
Prepare(); vector<int> x, y;
for (int i = 1; i <= 2 * n; i++) {
int nxt = Query(i);
if (nxt != cur) x.push_back(i);
else y.push_back(i);
cur = nxt;
}
cerr<<cost[43000];
Split(x, y, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
720 KB |
Output is correct |
2 |
Correct |
3 ms |
720 KB |
Output is correct |
3 |
Correct |
5 ms |
976 KB |
Output is correct |
4 |
Correct |
10 ms |
1332 KB |
Output is correct |
5 |
Correct |
19 ms |
1940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
15 |
Correct |
47 ms |
3980 KB |
Output is correct |
16 |
Correct |
54 ms |
3976 KB |
Output is correct |
17 |
Correct |
54 ms |
3996 KB |
Output is correct |
18 |
Correct |
55 ms |
3908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
15 |
Correct |
47 ms |
3980 KB |
Output is correct |
16 |
Correct |
54 ms |
3976 KB |
Output is correct |
17 |
Correct |
54 ms |
3996 KB |
Output is correct |
18 |
Correct |
55 ms |
3908 KB |
Output is correct |
19 |
Correct |
47 ms |
4168 KB |
Output is correct |
20 |
Correct |
48 ms |
4164 KB |
Output is correct |
21 |
Correct |
50 ms |
4208 KB |
Output is correct |
22 |
Correct |
49 ms |
4008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
15 |
Correct |
47 ms |
3980 KB |
Output is correct |
16 |
Correct |
54 ms |
3976 KB |
Output is correct |
17 |
Correct |
54 ms |
3996 KB |
Output is correct |
18 |
Correct |
55 ms |
3908 KB |
Output is correct |
19 |
Correct |
47 ms |
4168 KB |
Output is correct |
20 |
Correct |
48 ms |
4164 KB |
Output is correct |
21 |
Correct |
50 ms |
4208 KB |
Output is correct |
22 |
Correct |
49 ms |
4008 KB |
Output is correct |
23 |
Correct |
59 ms |
4324 KB |
Output is correct |
24 |
Correct |
51 ms |
4296 KB |
Output is correct |
25 |
Correct |
47 ms |
4312 KB |
Output is correct |
26 |
Correct |
45 ms |
4136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
15 |
Correct |
47 ms |
3980 KB |
Output is correct |
16 |
Correct |
54 ms |
3976 KB |
Output is correct |
17 |
Correct |
54 ms |
3996 KB |
Output is correct |
18 |
Correct |
55 ms |
3908 KB |
Output is correct |
19 |
Correct |
47 ms |
4168 KB |
Output is correct |
20 |
Correct |
48 ms |
4164 KB |
Output is correct |
21 |
Correct |
50 ms |
4208 KB |
Output is correct |
22 |
Correct |
49 ms |
4008 KB |
Output is correct |
23 |
Correct |
59 ms |
4324 KB |
Output is correct |
24 |
Correct |
51 ms |
4296 KB |
Output is correct |
25 |
Correct |
47 ms |
4312 KB |
Output is correct |
26 |
Correct |
45 ms |
4136 KB |
Output is correct |
27 |
Correct |
51 ms |
4336 KB |
Output is correct |
28 |
Correct |
52 ms |
4400 KB |
Output is correct |
29 |
Correct |
50 ms |
4352 KB |
Output is correct |
30 |
Correct |
60 ms |
4248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
15 |
Correct |
47 ms |
3980 KB |
Output is correct |
16 |
Correct |
54 ms |
3976 KB |
Output is correct |
17 |
Correct |
54 ms |
3996 KB |
Output is correct |
18 |
Correct |
55 ms |
3908 KB |
Output is correct |
19 |
Correct |
47 ms |
4168 KB |
Output is correct |
20 |
Correct |
48 ms |
4164 KB |
Output is correct |
21 |
Correct |
50 ms |
4208 KB |
Output is correct |
22 |
Correct |
49 ms |
4008 KB |
Output is correct |
23 |
Correct |
59 ms |
4324 KB |
Output is correct |
24 |
Correct |
51 ms |
4296 KB |
Output is correct |
25 |
Correct |
47 ms |
4312 KB |
Output is correct |
26 |
Correct |
45 ms |
4136 KB |
Output is correct |
27 |
Correct |
51 ms |
4336 KB |
Output is correct |
28 |
Correct |
52 ms |
4400 KB |
Output is correct |
29 |
Correct |
50 ms |
4352 KB |
Output is correct |
30 |
Correct |
60 ms |
4248 KB |
Output is correct |
31 |
Correct |
54 ms |
4540 KB |
Output is correct |
32 |
Correct |
58 ms |
4388 KB |
Output is correct |
33 |
Correct |
57 ms |
4420 KB |
Output is correct |
34 |
Correct |
47 ms |
4296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
720 KB |
Output is correct |
6 |
Correct |
3 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
976 KB |
Output is correct |
8 |
Correct |
10 ms |
1332 KB |
Output is correct |
9 |
Correct |
19 ms |
1940 KB |
Output is correct |
10 |
Correct |
2 ms |
720 KB |
Output is correct |
11 |
Correct |
12 ms |
1544 KB |
Output is correct |
12 |
Correct |
18 ms |
1972 KB |
Output is correct |
13 |
Correct |
17 ms |
2000 KB |
Output is correct |
14 |
Correct |
18 ms |
1948 KB |
Output is correct |
15 |
Correct |
47 ms |
3980 KB |
Output is correct |
16 |
Correct |
54 ms |
3976 KB |
Output is correct |
17 |
Correct |
54 ms |
3996 KB |
Output is correct |
18 |
Correct |
55 ms |
3908 KB |
Output is correct |
19 |
Correct |
47 ms |
4168 KB |
Output is correct |
20 |
Correct |
48 ms |
4164 KB |
Output is correct |
21 |
Correct |
50 ms |
4208 KB |
Output is correct |
22 |
Correct |
49 ms |
4008 KB |
Output is correct |
23 |
Correct |
59 ms |
4324 KB |
Output is correct |
24 |
Correct |
51 ms |
4296 KB |
Output is correct |
25 |
Correct |
47 ms |
4312 KB |
Output is correct |
26 |
Correct |
45 ms |
4136 KB |
Output is correct |
27 |
Correct |
51 ms |
4336 KB |
Output is correct |
28 |
Correct |
52 ms |
4400 KB |
Output is correct |
29 |
Correct |
50 ms |
4352 KB |
Output is correct |
30 |
Correct |
60 ms |
4248 KB |
Output is correct |
31 |
Correct |
54 ms |
4540 KB |
Output is correct |
32 |
Correct |
58 ms |
4388 KB |
Output is correct |
33 |
Correct |
57 ms |
4420 KB |
Output is correct |
34 |
Correct |
47 ms |
4296 KB |
Output is correct |
35 |
Incorrect |
53 ms |
4544 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |