# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
486184 |
2021-11-10T17:47:37 Z |
blue |
Minerals (JOI19_minerals) |
C++17 |
|
72 ms |
4180 KB |
#include "minerals.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <random>
#include <cmath>
using namespace std;
using vi = vector<int>;
const int maxN = 43'000;
int N;
vi mineral(1+2*maxN, 0);
int last_ans = 0;
int sz(vi& x)
{
return int(x.size());
}
random_device rd;
mt19937 g(rd());
void dnc(vi L, vi R, bool bL)
{
// cerr << "dnc " << b << " : ";
// for(int l:L) cerr << l << ' ';
// cerr << " | ";
// for(int r:R) cerr << r << ' ';
// cerr << "\n";
if(int(L.size()) == 1)
Answer(L[0], R[0]);
else if(int(L.size()) == 2)
{
if(!bL) last_ans = Query(L[0]);
else last_ans = Query(L[1]); //0 is active
int prev_ans = last_ans;
last_ans = Query(R[0]);
if(prev_ans == last_ans)
{
Answer(L[0], R[0]);
Answer(L[1], R[1]);
}
else
{
Answer(L[0], R[1]);
Answer(L[1], R[0]);
}
}
else
{
int K = int(L.size());
shuffle(L.begin(), L.end(), g);
double r = 0.6;
vi L1, L2;
if(bL)
{
for(int i = 0; i < int(K*r); i++)
L1.push_back(L[i]);
for(int i = int(K*r); i < K; i++)
L2.push_back(L[i]);
}
else
{
for(int i = 0; i < int(K*(1.0-r)); i++)
L1.push_back(L[i]);
for(int i = int(K*(1.0-r)); i < K; i++)
L2.push_back(L[i]);
}
if(bL)
{
for(int l: L2)
last_ans = Query(l);
}
else
{
for(int l: L1)
last_ans = Query(l);
}
vi R1, R2;
shuffle(R.begin(), R.end(), g);
for(int r:R)
{
if(sz(R1) == sz(L1))
{
R2.push_back(r);
}
else if(sz(R2) == sz(L2))
{
R1.push_back(r);
}
else
{
int prev_ans = last_ans;
last_ans = Query(r);
if(last_ans == prev_ans)
{
R1.push_back(r);
}
else
{
R2.push_back(r);
}
}
}
dnc(L1, R1, 1);
dnc(L2, R2, 0);
}
}
void Solve(int N_)
{
N = N_;
int ct = 0;
for(int i = 1; i <= 2*N; i++)
{
last_ans = Query(i);
if(last_ans > ct)
{
// cerr << "increasing ct = " << ct << " at " << i << '\n';
ct++;
mineral[i] = ct;
// cerr << i << " : " << mineral[i] << '\n';
}
}
// cerr << "check\n";
// for(int i = 1; i <= 2*N; i++) cerr << i << " : " << mineral[i] << '\n';
vi leftval, rightval;
for(int i = 1; i <= 2*N; i++)
{
if(mineral[i])
leftval.push_back(i);
else
rightval.push_back(i);
}
dnc(leftval, rightval, 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
712 KB |
Output is correct |
2 |
Correct |
2 ms |
712 KB |
Output is correct |
3 |
Correct |
5 ms |
968 KB |
Output is correct |
4 |
Correct |
12 ms |
1224 KB |
Output is correct |
5 |
Correct |
19 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
15 |
Correct |
55 ms |
3784 KB |
Output is correct |
16 |
Correct |
58 ms |
3776 KB |
Output is correct |
17 |
Correct |
55 ms |
3776 KB |
Output is correct |
18 |
Correct |
56 ms |
3596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
15 |
Correct |
55 ms |
3784 KB |
Output is correct |
16 |
Correct |
58 ms |
3776 KB |
Output is correct |
17 |
Correct |
55 ms |
3776 KB |
Output is correct |
18 |
Correct |
56 ms |
3596 KB |
Output is correct |
19 |
Correct |
72 ms |
3888 KB |
Output is correct |
20 |
Correct |
59 ms |
3772 KB |
Output is correct |
21 |
Correct |
56 ms |
3872 KB |
Output is correct |
22 |
Correct |
60 ms |
3652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
15 |
Correct |
55 ms |
3784 KB |
Output is correct |
16 |
Correct |
58 ms |
3776 KB |
Output is correct |
17 |
Correct |
55 ms |
3776 KB |
Output is correct |
18 |
Correct |
56 ms |
3596 KB |
Output is correct |
19 |
Correct |
72 ms |
3888 KB |
Output is correct |
20 |
Correct |
59 ms |
3772 KB |
Output is correct |
21 |
Correct |
56 ms |
3872 KB |
Output is correct |
22 |
Correct |
60 ms |
3652 KB |
Output is correct |
23 |
Correct |
58 ms |
3888 KB |
Output is correct |
24 |
Correct |
56 ms |
3908 KB |
Output is correct |
25 |
Correct |
58 ms |
3952 KB |
Output is correct |
26 |
Correct |
58 ms |
3760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
15 |
Correct |
55 ms |
3784 KB |
Output is correct |
16 |
Correct |
58 ms |
3776 KB |
Output is correct |
17 |
Correct |
55 ms |
3776 KB |
Output is correct |
18 |
Correct |
56 ms |
3596 KB |
Output is correct |
19 |
Correct |
72 ms |
3888 KB |
Output is correct |
20 |
Correct |
59 ms |
3772 KB |
Output is correct |
21 |
Correct |
56 ms |
3872 KB |
Output is correct |
22 |
Correct |
60 ms |
3652 KB |
Output is correct |
23 |
Correct |
58 ms |
3888 KB |
Output is correct |
24 |
Correct |
56 ms |
3908 KB |
Output is correct |
25 |
Correct |
58 ms |
3952 KB |
Output is correct |
26 |
Correct |
58 ms |
3760 KB |
Output is correct |
27 |
Correct |
59 ms |
4044 KB |
Output is correct |
28 |
Correct |
64 ms |
4028 KB |
Output is correct |
29 |
Correct |
62 ms |
4044 KB |
Output is correct |
30 |
Correct |
65 ms |
3784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
15 |
Correct |
55 ms |
3784 KB |
Output is correct |
16 |
Correct |
58 ms |
3776 KB |
Output is correct |
17 |
Correct |
55 ms |
3776 KB |
Output is correct |
18 |
Correct |
56 ms |
3596 KB |
Output is correct |
19 |
Correct |
72 ms |
3888 KB |
Output is correct |
20 |
Correct |
59 ms |
3772 KB |
Output is correct |
21 |
Correct |
56 ms |
3872 KB |
Output is correct |
22 |
Correct |
60 ms |
3652 KB |
Output is correct |
23 |
Correct |
58 ms |
3888 KB |
Output is correct |
24 |
Correct |
56 ms |
3908 KB |
Output is correct |
25 |
Correct |
58 ms |
3952 KB |
Output is correct |
26 |
Correct |
58 ms |
3760 KB |
Output is correct |
27 |
Correct |
59 ms |
4044 KB |
Output is correct |
28 |
Correct |
64 ms |
4028 KB |
Output is correct |
29 |
Correct |
62 ms |
4044 KB |
Output is correct |
30 |
Correct |
65 ms |
3784 KB |
Output is correct |
31 |
Correct |
61 ms |
4064 KB |
Output is correct |
32 |
Correct |
66 ms |
4128 KB |
Output is correct |
33 |
Correct |
68 ms |
4144 KB |
Output is correct |
34 |
Correct |
58 ms |
3904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
584 KB |
Output is correct |
2 |
Correct |
0 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
5 ms |
968 KB |
Output is correct |
8 |
Correct |
12 ms |
1224 KB |
Output is correct |
9 |
Correct |
19 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
1528 KB |
Output is correct |
12 |
Correct |
21 ms |
1936 KB |
Output is correct |
13 |
Correct |
21 ms |
1900 KB |
Output is correct |
14 |
Correct |
20 ms |
1872 KB |
Output is correct |
15 |
Correct |
55 ms |
3784 KB |
Output is correct |
16 |
Correct |
58 ms |
3776 KB |
Output is correct |
17 |
Correct |
55 ms |
3776 KB |
Output is correct |
18 |
Correct |
56 ms |
3596 KB |
Output is correct |
19 |
Correct |
72 ms |
3888 KB |
Output is correct |
20 |
Correct |
59 ms |
3772 KB |
Output is correct |
21 |
Correct |
56 ms |
3872 KB |
Output is correct |
22 |
Correct |
60 ms |
3652 KB |
Output is correct |
23 |
Correct |
58 ms |
3888 KB |
Output is correct |
24 |
Correct |
56 ms |
3908 KB |
Output is correct |
25 |
Correct |
58 ms |
3952 KB |
Output is correct |
26 |
Correct |
58 ms |
3760 KB |
Output is correct |
27 |
Correct |
59 ms |
4044 KB |
Output is correct |
28 |
Correct |
64 ms |
4028 KB |
Output is correct |
29 |
Correct |
62 ms |
4044 KB |
Output is correct |
30 |
Correct |
65 ms |
3784 KB |
Output is correct |
31 |
Correct |
61 ms |
4064 KB |
Output is correct |
32 |
Correct |
66 ms |
4128 KB |
Output is correct |
33 |
Correct |
68 ms |
4144 KB |
Output is correct |
34 |
Correct |
58 ms |
3904 KB |
Output is correct |
35 |
Correct |
64 ms |
4180 KB |
Output is correct |
36 |
Correct |
67 ms |
4132 KB |
Output is correct |
37 |
Correct |
62 ms |
4136 KB |
Output is correct |
38 |
Correct |
72 ms |
4004 KB |
Output is correct |