#include "minerals.h"
#include<vector>
#include<set>
#include<random>
#include<algorithm>
#include<iostream>
using namespace std;
int n, s;
//2nlog(2n)
random_device rd;
mt19937 g(rd());
int szdp = 43000;//getting the szdp bigger, trinary search
vector<int> dp0(szdp + 1),nxt0(szdp + 1), dp1(szdp+1), nxt1(szdp+1);
//vector<int> cp0(szdp + 1), cxt0(szdp + 1), cp1(szdp + 1), cxt1(szdp + 1);
void solve(vector<int>& in, vector<int>& rest, int f1, int f2) {
//cout << "solve "<< in.size() << ' ' << rest.size() << ' ' << flag << endl;
//shuffle(in.begin(), in.end(), g);
//shuffle(rest.begin(), rest.end(), g);
if (in.size() == 1) { Answer(in[0], rest[0]); return; }
vector<int> in1, in2;
int sz1 = in.size() / 2;
if (in.size() <= szdp) sz1 = in.size() - nxt0[in.size()];
int sz = 0;
if (f1) {
for (int i = 0; i < sz1; i++) in1.push_back(in[i]);
for (int i = sz1; i < in.size(); i++) in2.push_back(in[i]);
for (int i : in2) sz = Query(i);
}
else {
sz1 = in.size() - sz1;
for (int i = 0; i < sz1; i++) in1.push_back(in[i]);
for (int i = sz1; i < in.size(); i++) in2.push_back(in[i]);
for (int i : in1) sz = Query(i);
}
vector<int> rest1, rest2;
for (int j : rest) {
//if (rest1.size() == in1.size()) { rest2.push_back(j); continue; }
//if (rest2.size() == in2.size()) { rest1.push_back(j); continue; }
int u = Query(j);
if (u == sz) rest1.push_back(j);
else {
rest2.push_back(j);
sz = u;
}
}
solve(in1, rest1, 1, 1 - f2);
solve(in2, rest2, 0, 1 - f2);
}
void Solve(int N) {
//4 dp's, or calculate right the 2 dp's
dp0[1] = dp1[1] = 0; //the xor
for (int i = 2; i <= szdp; i++) {
int l = 1, r = i / 2, m;
while (r > l) {
m = (l + r) / 2;
int vm = dp0[m] + dp0[i - m] + m + i;
int vm1 = dp0[m+1] + dp0[i - m - 1] + m + 1 + i;
if (vm > vm1) l = m + 1;
else r = m;
}
dp0[i] = dp0[l] + dp0[i - l] + l + i;
nxt0[i] = l;
//if (dp1[i] != dp[i]) { cout << i << ' ' << dp[i] << ' ' << dp1[i] << ' ' << "ERROR!!!" << endl; break; }
}
/*cp0[1] = cp1[1] = 0;
for (int i = 2; i <= 10000; i++) {
cp0[i] = cp1[i] = 1e9;
for (int j = 1; j <= i / 2; j++) {
if (cp0[j] + cp1[i - j] + j + i < cp0[i]) {
cp0[i] = cp0[j] + cp1[i - j] + j + i;
cxt0[i] = j;
}
if (cp0[j] + cp0[i - j] + 2 * j + i < cp1[i]) {
cp1[i] = cp0[j] + cp0[i - j] + 2 * j + i;
cxt1[i] = j;
}
}
if (cp0[i] != dp0[i] || cp1[i] != dp1[i]) cout << "ERROR!\n";
}*/
//for (int u = 38000; u <= 43000; u += 1000) cout << u << ' ' << 2 * u + dp0[u] << endl;
n = N; s = n << 1;
int sz = 0;
vector<int> in, rest;
vector<int> vec(s);
for (int i = 0; i < s; i++)vec[i] = i + 1;
//shuffle(vec.begin(), vec.end(), g);
for (int i : vec) {
//if (in.size() < n) {
int u = Query(i);
if (u > sz) {
sz = u;
in.push_back(i);
}
else {
rest.push_back(i);
}
}
solve(in, rest, 1, 1);
}
Compilation message
minerals.cpp: In function 'void solve(std::vector<int>&, std::vector<int>&, int, int)':
minerals.cpp:24:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | if (in.size() <= szdp) sz1 = in.size() - nxt0[in.size()];
| ~~~~~~~~~~^~~~~~~
minerals.cpp:31:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = sz1; i < in.size(); i++) in2.push_back(in[i]);
| ~~^~~~~~~~~~~
minerals.cpp:37:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = sz1; i < in.size(); i++) in2.push_back(in[i]);
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1112 KB |
Output is correct |
2 |
Correct |
5 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1368 KB |
Output is correct |
4 |
Correct |
8 ms |
1624 KB |
Output is correct |
5 |
Correct |
12 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
15 |
Correct |
26 ms |
3988 KB |
Output is correct |
16 |
Correct |
27 ms |
3992 KB |
Output is correct |
17 |
Correct |
28 ms |
4044 KB |
Output is correct |
18 |
Correct |
22 ms |
3888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
15 |
Correct |
26 ms |
3988 KB |
Output is correct |
16 |
Correct |
27 ms |
3992 KB |
Output is correct |
17 |
Correct |
28 ms |
4044 KB |
Output is correct |
18 |
Correct |
22 ms |
3888 KB |
Output is correct |
19 |
Correct |
26 ms |
4184 KB |
Output is correct |
20 |
Correct |
27 ms |
3992 KB |
Output is correct |
21 |
Correct |
22 ms |
4488 KB |
Output is correct |
22 |
Correct |
21 ms |
3920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
15 |
Correct |
26 ms |
3988 KB |
Output is correct |
16 |
Correct |
27 ms |
3992 KB |
Output is correct |
17 |
Correct |
28 ms |
4044 KB |
Output is correct |
18 |
Correct |
22 ms |
3888 KB |
Output is correct |
19 |
Correct |
26 ms |
4184 KB |
Output is correct |
20 |
Correct |
27 ms |
3992 KB |
Output is correct |
21 |
Correct |
22 ms |
4488 KB |
Output is correct |
22 |
Correct |
21 ms |
3920 KB |
Output is correct |
23 |
Correct |
27 ms |
3920 KB |
Output is correct |
24 |
Correct |
27 ms |
4176 KB |
Output is correct |
25 |
Correct |
22 ms |
4396 KB |
Output is correct |
26 |
Correct |
22 ms |
3992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
15 |
Correct |
26 ms |
3988 KB |
Output is correct |
16 |
Correct |
27 ms |
3992 KB |
Output is correct |
17 |
Correct |
28 ms |
4044 KB |
Output is correct |
18 |
Correct |
22 ms |
3888 KB |
Output is correct |
19 |
Correct |
26 ms |
4184 KB |
Output is correct |
20 |
Correct |
27 ms |
3992 KB |
Output is correct |
21 |
Correct |
22 ms |
4488 KB |
Output is correct |
22 |
Correct |
21 ms |
3920 KB |
Output is correct |
23 |
Correct |
27 ms |
3920 KB |
Output is correct |
24 |
Correct |
27 ms |
4176 KB |
Output is correct |
25 |
Correct |
22 ms |
4396 KB |
Output is correct |
26 |
Correct |
22 ms |
3992 KB |
Output is correct |
27 |
Correct |
34 ms |
4180 KB |
Output is correct |
28 |
Correct |
31 ms |
4252 KB |
Output is correct |
29 |
Correct |
23 ms |
4000 KB |
Output is correct |
30 |
Correct |
23 ms |
3920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
15 |
Correct |
26 ms |
3988 KB |
Output is correct |
16 |
Correct |
27 ms |
3992 KB |
Output is correct |
17 |
Correct |
28 ms |
4044 KB |
Output is correct |
18 |
Correct |
22 ms |
3888 KB |
Output is correct |
19 |
Correct |
26 ms |
4184 KB |
Output is correct |
20 |
Correct |
27 ms |
3992 KB |
Output is correct |
21 |
Correct |
22 ms |
4488 KB |
Output is correct |
22 |
Correct |
21 ms |
3920 KB |
Output is correct |
23 |
Correct |
27 ms |
3920 KB |
Output is correct |
24 |
Correct |
27 ms |
4176 KB |
Output is correct |
25 |
Correct |
22 ms |
4396 KB |
Output is correct |
26 |
Correct |
22 ms |
3992 KB |
Output is correct |
27 |
Correct |
34 ms |
4180 KB |
Output is correct |
28 |
Correct |
31 ms |
4252 KB |
Output is correct |
29 |
Correct |
23 ms |
4000 KB |
Output is correct |
30 |
Correct |
23 ms |
3920 KB |
Output is correct |
31 |
Incorrect |
32 ms |
4476 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1364 KB |
Output is correct |
2 |
Correct |
4 ms |
1112 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
4 ms |
1112 KB |
Output is correct |
6 |
Correct |
5 ms |
1368 KB |
Output is correct |
7 |
Correct |
5 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1624 KB |
Output is correct |
9 |
Correct |
12 ms |
2252 KB |
Output is correct |
10 |
Correct |
4 ms |
1112 KB |
Output is correct |
11 |
Correct |
9 ms |
1724 KB |
Output is correct |
12 |
Correct |
12 ms |
2392 KB |
Output is correct |
13 |
Correct |
10 ms |
2312 KB |
Output is correct |
14 |
Correct |
10 ms |
2136 KB |
Output is correct |
15 |
Correct |
26 ms |
3988 KB |
Output is correct |
16 |
Correct |
27 ms |
3992 KB |
Output is correct |
17 |
Correct |
28 ms |
4044 KB |
Output is correct |
18 |
Correct |
22 ms |
3888 KB |
Output is correct |
19 |
Correct |
26 ms |
4184 KB |
Output is correct |
20 |
Correct |
27 ms |
3992 KB |
Output is correct |
21 |
Correct |
22 ms |
4488 KB |
Output is correct |
22 |
Correct |
21 ms |
3920 KB |
Output is correct |
23 |
Correct |
27 ms |
3920 KB |
Output is correct |
24 |
Correct |
27 ms |
4176 KB |
Output is correct |
25 |
Correct |
22 ms |
4396 KB |
Output is correct |
26 |
Correct |
22 ms |
3992 KB |
Output is correct |
27 |
Correct |
34 ms |
4180 KB |
Output is correct |
28 |
Correct |
31 ms |
4252 KB |
Output is correct |
29 |
Correct |
23 ms |
4000 KB |
Output is correct |
30 |
Correct |
23 ms |
3920 KB |
Output is correct |
31 |
Incorrect |
32 ms |
4476 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |