#include <bits/stdc++.h>
#include "minerals.h"
using namespace std;
#define sz(a) (int)a.size()
mt19937 rng(69);
//b - valoarea elementului, stateul (aprins/stins)
int ans = 0, prevans = -1;
void rec(vector<int> a, vector<pair<int, int>> b) {
if(b.empty() || a.empty()) return;
if(sz(b) == 1) {
for(auto x: a) Answer(x, b[0].first);
return;
}
int mid = sz(b) / 2;
vector<pair<int, int>> left, right;
for(int i = 0; i < sz(b); ++i) {
if(i < mid) left.push_back(b[i]);
else right.push_back(b[i]);
}
for(auto& x: left) {
if(!x.second) {
prevans = Query(x.first);
x.second = 1;
}
}
for(auto& x: right) {
if(x.second) {
prevans = Query(x.first);
x.second = 0;
}
}
vector<int> first_half, second_half;
for(auto x: a) {
int ans = Query(x);
if(ans == prevans) {
first_half.push_back(x);
} else {
second_half.push_back(x);
}
prevans = ans;
}
rec(first_half, left);
rec(second_half, right);
}
void Solve(int n) {
vector<int> p1, p2;
vector<int> bulanea(2 * n);
iota(bulanea.begin(), bulanea.end(), 1);
shuffle(bulanea.begin(), bulanea.end(), rng);
for(int i: bulanea) {
ans = Query(i);
if(ans == prevans) {
p2.push_back(i);
} else {
p1.push_back(i);
}
prevans = ans;
}
assert(sz(p1) == n && sz(p2) == n);
vector<pair<int, int>> b;
for(auto x: p1) b.push_back({x, 1});
rec(p2, b);
}
/*
4
1 5
2 6
3 4
7 8
*/
// g++ -Wall -lm -static -DEVAL -o minerals -O2 minerals.cpp grader.cpp -std=c++17
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
1108 KB |
Output is correct |
5 |
Correct |
12 ms |
1812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
15 |
Correct |
32 ms |
4336 KB |
Output is correct |
16 |
Correct |
31 ms |
4416 KB |
Output is correct |
17 |
Correct |
36 ms |
4420 KB |
Output is correct |
18 |
Correct |
33 ms |
4264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
15 |
Correct |
32 ms |
4336 KB |
Output is correct |
16 |
Correct |
31 ms |
4416 KB |
Output is correct |
17 |
Correct |
36 ms |
4420 KB |
Output is correct |
18 |
Correct |
33 ms |
4264 KB |
Output is correct |
19 |
Correct |
35 ms |
4432 KB |
Output is correct |
20 |
Correct |
34 ms |
4468 KB |
Output is correct |
21 |
Correct |
32 ms |
4504 KB |
Output is correct |
22 |
Correct |
35 ms |
4412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
15 |
Correct |
32 ms |
4336 KB |
Output is correct |
16 |
Correct |
31 ms |
4416 KB |
Output is correct |
17 |
Correct |
36 ms |
4420 KB |
Output is correct |
18 |
Correct |
33 ms |
4264 KB |
Output is correct |
19 |
Correct |
35 ms |
4432 KB |
Output is correct |
20 |
Correct |
34 ms |
4468 KB |
Output is correct |
21 |
Correct |
32 ms |
4504 KB |
Output is correct |
22 |
Correct |
35 ms |
4412 KB |
Output is correct |
23 |
Correct |
42 ms |
4596 KB |
Output is correct |
24 |
Correct |
34 ms |
4720 KB |
Output is correct |
25 |
Correct |
40 ms |
4528 KB |
Output is correct |
26 |
Correct |
34 ms |
4380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
15 |
Correct |
32 ms |
4336 KB |
Output is correct |
16 |
Correct |
31 ms |
4416 KB |
Output is correct |
17 |
Correct |
36 ms |
4420 KB |
Output is correct |
18 |
Correct |
33 ms |
4264 KB |
Output is correct |
19 |
Correct |
35 ms |
4432 KB |
Output is correct |
20 |
Correct |
34 ms |
4468 KB |
Output is correct |
21 |
Correct |
32 ms |
4504 KB |
Output is correct |
22 |
Correct |
35 ms |
4412 KB |
Output is correct |
23 |
Correct |
42 ms |
4596 KB |
Output is correct |
24 |
Correct |
34 ms |
4720 KB |
Output is correct |
25 |
Correct |
40 ms |
4528 KB |
Output is correct |
26 |
Correct |
34 ms |
4380 KB |
Output is correct |
27 |
Incorrect |
34 ms |
4680 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
15 |
Correct |
32 ms |
4336 KB |
Output is correct |
16 |
Correct |
31 ms |
4416 KB |
Output is correct |
17 |
Correct |
36 ms |
4420 KB |
Output is correct |
18 |
Correct |
33 ms |
4264 KB |
Output is correct |
19 |
Correct |
35 ms |
4432 KB |
Output is correct |
20 |
Correct |
34 ms |
4468 KB |
Output is correct |
21 |
Correct |
32 ms |
4504 KB |
Output is correct |
22 |
Correct |
35 ms |
4412 KB |
Output is correct |
23 |
Correct |
42 ms |
4596 KB |
Output is correct |
24 |
Correct |
34 ms |
4720 KB |
Output is correct |
25 |
Correct |
40 ms |
4528 KB |
Output is correct |
26 |
Correct |
34 ms |
4380 KB |
Output is correct |
27 |
Incorrect |
34 ms |
4680 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
12 ms |
1812 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
1360 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
11 ms |
1876 KB |
Output is correct |
14 |
Correct |
11 ms |
1744 KB |
Output is correct |
15 |
Correct |
32 ms |
4336 KB |
Output is correct |
16 |
Correct |
31 ms |
4416 KB |
Output is correct |
17 |
Correct |
36 ms |
4420 KB |
Output is correct |
18 |
Correct |
33 ms |
4264 KB |
Output is correct |
19 |
Correct |
35 ms |
4432 KB |
Output is correct |
20 |
Correct |
34 ms |
4468 KB |
Output is correct |
21 |
Correct |
32 ms |
4504 KB |
Output is correct |
22 |
Correct |
35 ms |
4412 KB |
Output is correct |
23 |
Correct |
42 ms |
4596 KB |
Output is correct |
24 |
Correct |
34 ms |
4720 KB |
Output is correct |
25 |
Correct |
40 ms |
4528 KB |
Output is correct |
26 |
Correct |
34 ms |
4380 KB |
Output is correct |
27 |
Incorrect |
34 ms |
4680 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |