#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct RNG {
int operator () (int n) {
return rnd(n);
}
};
void solve(vector<int> u, vector<int> v, int f) {
if(u.empty()) return;
if(u.size() == 1) {
Answer(u.back(), v.back());
return;
}
random_shuffle(u.begin(), u.end(), RNG());
int mid = u.size() >> 1;
int last;
if(f) {
for(int i = mid; i < v.size(); i++) {
last = Query(v[i]);
}
} else {
for(int i = 0; i < mid; i++) {
last = Query(v[i]);
}
}
vector<int> lu, lv(v.begin(), v.begin() + mid), ru, rv(v.begin() + mid, v.end());
for(int i = 0; i < u.size(); i++) {
if(lu.size() == lv.size()) {
ru.emplace_back(u[i]);
} else if(ru.size() == rv.size()) {
lu.emplace_back(u[i]);
} else {
int rep = Query(u[i]);
if(rep == last) {
lu.emplace_back(u[i]);
} else {
ru.emplace_back(u[i]);
}
last = rep;
}
}
solve(lu, lv, 1);
solve(ru, rv, 0);
}
void split(vector<int> v) {
if(v.size() == 2) return Answer(v[0], v[1]);
vector<int> l, r;
int last = -1;
for(int i = 0; i < v.size(); i++) {
if(r.size() == v.size() / 2) {
l.emplace_back(v[i]);
continue;
}
int rep = Query(v[i]);
if(rep == last) {
l.emplace_back(v[i]);
} else {
r.emplace_back(v[i]);
} last = rep;
}
solve(l, r, 1);
}
void Solve(int N) {
vector<int> v(2 * N);
iota(v.begin(), v.end(), 1);
split(v);
}
Compilation message
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = mid; i < v.size(); i++) {
~~^~~~~~~~~~
minerals.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < u.size(); i++) {
~~^~~~~~~~~~
minerals.cpp: In function 'void split(std::vector<int>)':
minerals.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:40:4: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(rep == last) {
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
4 |
Correct |
11 ms |
1024 KB |
Output is correct |
5 |
Correct |
21 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
15 |
Correct |
58 ms |
3740 KB |
Output is correct |
16 |
Correct |
59 ms |
3696 KB |
Output is correct |
17 |
Correct |
53 ms |
3664 KB |
Output is correct |
18 |
Correct |
57 ms |
3636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
15 |
Correct |
58 ms |
3740 KB |
Output is correct |
16 |
Correct |
59 ms |
3696 KB |
Output is correct |
17 |
Correct |
53 ms |
3664 KB |
Output is correct |
18 |
Correct |
57 ms |
3636 KB |
Output is correct |
19 |
Correct |
66 ms |
3740 KB |
Output is correct |
20 |
Correct |
63 ms |
3732 KB |
Output is correct |
21 |
Correct |
57 ms |
3832 KB |
Output is correct |
22 |
Correct |
55 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
15 |
Correct |
58 ms |
3740 KB |
Output is correct |
16 |
Correct |
59 ms |
3696 KB |
Output is correct |
17 |
Correct |
53 ms |
3664 KB |
Output is correct |
18 |
Correct |
57 ms |
3636 KB |
Output is correct |
19 |
Correct |
66 ms |
3740 KB |
Output is correct |
20 |
Correct |
63 ms |
3732 KB |
Output is correct |
21 |
Correct |
57 ms |
3832 KB |
Output is correct |
22 |
Correct |
55 ms |
3584 KB |
Output is correct |
23 |
Correct |
66 ms |
3836 KB |
Output is correct |
24 |
Correct |
62 ms |
4004 KB |
Output is correct |
25 |
Correct |
57 ms |
3844 KB |
Output is correct |
26 |
Correct |
57 ms |
3688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
15 |
Correct |
58 ms |
3740 KB |
Output is correct |
16 |
Correct |
59 ms |
3696 KB |
Output is correct |
17 |
Correct |
53 ms |
3664 KB |
Output is correct |
18 |
Correct |
57 ms |
3636 KB |
Output is correct |
19 |
Correct |
66 ms |
3740 KB |
Output is correct |
20 |
Correct |
63 ms |
3732 KB |
Output is correct |
21 |
Correct |
57 ms |
3832 KB |
Output is correct |
22 |
Correct |
55 ms |
3584 KB |
Output is correct |
23 |
Correct |
66 ms |
3836 KB |
Output is correct |
24 |
Correct |
62 ms |
4004 KB |
Output is correct |
25 |
Correct |
57 ms |
3844 KB |
Output is correct |
26 |
Correct |
57 ms |
3688 KB |
Output is correct |
27 |
Correct |
66 ms |
4084 KB |
Output is correct |
28 |
Correct |
65 ms |
3964 KB |
Output is correct |
29 |
Correct |
59 ms |
4028 KB |
Output is correct |
30 |
Correct |
60 ms |
3888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
15 |
Correct |
58 ms |
3740 KB |
Output is correct |
16 |
Correct |
59 ms |
3696 KB |
Output is correct |
17 |
Correct |
53 ms |
3664 KB |
Output is correct |
18 |
Correct |
57 ms |
3636 KB |
Output is correct |
19 |
Correct |
66 ms |
3740 KB |
Output is correct |
20 |
Correct |
63 ms |
3732 KB |
Output is correct |
21 |
Correct |
57 ms |
3832 KB |
Output is correct |
22 |
Correct |
55 ms |
3584 KB |
Output is correct |
23 |
Correct |
66 ms |
3836 KB |
Output is correct |
24 |
Correct |
62 ms |
4004 KB |
Output is correct |
25 |
Correct |
57 ms |
3844 KB |
Output is correct |
26 |
Correct |
57 ms |
3688 KB |
Output is correct |
27 |
Correct |
66 ms |
4084 KB |
Output is correct |
28 |
Correct |
65 ms |
3964 KB |
Output is correct |
29 |
Correct |
59 ms |
4028 KB |
Output is correct |
30 |
Correct |
60 ms |
3888 KB |
Output is correct |
31 |
Correct |
69 ms |
4136 KB |
Output is correct |
32 |
Correct |
77 ms |
4016 KB |
Output is correct |
33 |
Correct |
63 ms |
4144 KB |
Output is correct |
34 |
Correct |
65 ms |
3892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
11 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
15 ms |
1280 KB |
Output is correct |
12 |
Correct |
22 ms |
1536 KB |
Output is correct |
13 |
Correct |
24 ms |
1656 KB |
Output is correct |
14 |
Correct |
21 ms |
1596 KB |
Output is correct |
15 |
Correct |
58 ms |
3740 KB |
Output is correct |
16 |
Correct |
59 ms |
3696 KB |
Output is correct |
17 |
Correct |
53 ms |
3664 KB |
Output is correct |
18 |
Correct |
57 ms |
3636 KB |
Output is correct |
19 |
Correct |
66 ms |
3740 KB |
Output is correct |
20 |
Correct |
63 ms |
3732 KB |
Output is correct |
21 |
Correct |
57 ms |
3832 KB |
Output is correct |
22 |
Correct |
55 ms |
3584 KB |
Output is correct |
23 |
Correct |
66 ms |
3836 KB |
Output is correct |
24 |
Correct |
62 ms |
4004 KB |
Output is correct |
25 |
Correct |
57 ms |
3844 KB |
Output is correct |
26 |
Correct |
57 ms |
3688 KB |
Output is correct |
27 |
Correct |
66 ms |
4084 KB |
Output is correct |
28 |
Correct |
65 ms |
3964 KB |
Output is correct |
29 |
Correct |
59 ms |
4028 KB |
Output is correct |
30 |
Correct |
60 ms |
3888 KB |
Output is correct |
31 |
Correct |
69 ms |
4136 KB |
Output is correct |
32 |
Correct |
77 ms |
4016 KB |
Output is correct |
33 |
Correct |
63 ms |
4144 KB |
Output is correct |
34 |
Correct |
65 ms |
3892 KB |
Output is correct |
35 |
Incorrect |
67 ms |
4096 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |