#include "koala.h"
#include <algorithm>
#include <vector>
std::vector<bool> query(const std::vector<int> &vec)
{
static int B[105], R[105];
int n = vec.size();
for (int i = 0; i < n; i++)
B[i] = vec[i];
playRound(B, R);
std::vector<bool> res(n);
for (int i = 0; i < n; i++)
res[i] = R[i] > B[i];
return res;
}
int minValue(int n, int m)
{
std::vector<int> vec(n);
vec[0] = 1;
auto res = query(vec);
for (int i = 0; i < n; i++)
{
if (!res[i])
return i;
}
return -1;
}
int maxValue(int n, int m)
{
std::vector<bool> in(n, true);
int cnt = n;
while (cnt > 1)
{
int w = m / cnt;
std::vector<int> vec(n);
for (int i = 0; i < n; i++)
vec[i] = in[i] ? w : 0;
auto res = query(vec);
cnt = 0;
for (int i = 0; i < n; i++)
{
in[i] = in[i] & res[i];
cnt += in[i];
}
}
for (int i = 0; i < n; i++)
{
if (in[i])
return i;
}
return -1;
}
int greaterValue(int n, int m)
{
std::vector<int> vec(n);
vec[0] = vec[1] = 4;
auto res = query(vec);
if (res[0] != res[1])
return res[1];
if (res[0])
{
vec[0] = vec[1] = 8;
return query(vec)[1];
}
vec[0] = vec[1] = 2;
res = query(vec);
if (res[0] != res[1])
return res[1];
vec[0] = vec[1] = 1;
return query(vec)[1];
}
int idx[105], val[105], n;
inline int calc_sum(int l, int r) { return (l + r) * (r - l + 1) / 2; }
int get_val(int l, int r)
{
int mn = 1, mx = n / (r - l + 1);
while (mn <= mx)
{
int mid = mn + mx >> 1, rem = 0, cur = r, left = 0;
for (int i = 0; i < n; i++)
{
if (i < l || i > r)
val[i] = 1;
else
{
val[i] = 0;
rem++;
}
}
while (rem > mid)
{
val[cur--] = mid + 1;
rem -= mid + 1;
}
val[cur] = rem;
while (true)
{
int goal = mid + 1 - val[cur];
if (left + goal > l || calc_sum(left + 1, left + goal) >= cur)
break;
for (int i = left; i < left + goal; i++)
{
val[i]--;
val[cur]++;
}
left += goal;
if (--cur < l)
break;
}
if (val[l] > mid)
mn = mid + 1;
else if (val[r] <= mid)
mx = mid - 1;
else
return mid;
}
throw;
}
void solve(int l, int r, const std::vector<int> &vec)
{
if (l == r)
{
idx[l] = vec[0];
return;
}
int w = get_val(l, r);
std::vector<int> qry(n);
for (int i = 0; i < n; i++)
qry[i] = std::binary_search(vec.begin(), vec.end(), i) ? w : 0;
auto res = query(qry);
std::vector<int> vec_l, vec_r;
for (int u : vec)
(res[u] ? vec_r : vec_l).push_back(u);
solve(l, r - vec_r.size(), vec_l);
solve(r - vec_r.size() + 1, r, vec_r);
}
void allValues(int _n, int m, int *arr)
{
n = _n;
std::vector<int> seq(n);
for (int i = 0; i < n; i++)
seq[i] = i;
if (m == n)
{
solve(0, n - 1, seq);
for (int i = 0; i < n; i++)
arr[idx[i]] = i + 1;
return;
}
std::stable_sort(seq.begin(), seq.end(), [&] (int x, int y)
{
std::vector<int> vec(n, 0);
vec[x] = vec[y] = n;
return (bool)query(vec)[y];
});
for (int i = 0; i < n; i++)
arr[seq[i]] = i + 1;
}
Compilation message
koala.cpp: In function 'int get_val(int, int)':
koala.cpp:79:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = mn + mx >> 1, rem = 0, cur = r, left = 0;
~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
9 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
256 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
15 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
648 KB |
Output is correct |
2 |
Correct |
73 ms |
384 KB |
Output is correct |
3 |
Correct |
82 ms |
384 KB |
Output is correct |
4 |
Correct |
63 ms |
504 KB |
Output is correct |
5 |
Correct |
89 ms |
504 KB |
Output is correct |
6 |
Correct |
67 ms |
504 KB |
Output is correct |
7 |
Correct |
65 ms |
420 KB |
Output is correct |
8 |
Correct |
64 ms |
432 KB |
Output is correct |
9 |
Correct |
80 ms |
504 KB |
Output is correct |
10 |
Correct |
68 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
256 KB |
Output is correct |
2 |
Correct |
41 ms |
412 KB |
Output is correct |
3 |
Correct |
34 ms |
256 KB |
Output is correct |
4 |
Correct |
37 ms |
256 KB |
Output is correct |
5 |
Correct |
42 ms |
256 KB |
Output is correct |
6 |
Correct |
36 ms |
384 KB |
Output is correct |
7 |
Correct |
38 ms |
384 KB |
Output is correct |
8 |
Correct |
31 ms |
384 KB |
Output is correct |
9 |
Correct |
31 ms |
396 KB |
Output is correct |
10 |
Correct |
45 ms |
384 KB |
Output is correct |
11 |
Correct |
34 ms |
384 KB |
Output is correct |
12 |
Correct |
16 ms |
384 KB |
Output is correct |
13 |
Correct |
34 ms |
384 KB |
Output is correct |
14 |
Correct |
33 ms |
384 KB |
Output is correct |
15 |
Correct |
35 ms |
256 KB |
Output is correct |
16 |
Correct |
35 ms |
368 KB |
Output is correct |
17 |
Correct |
34 ms |
380 KB |
Output is correct |
18 |
Correct |
33 ms |
376 KB |
Output is correct |
19 |
Correct |
34 ms |
256 KB |
Output is correct |
20 |
Correct |
30 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
18 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
256 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
256 KB |
Output is correct |
29 |
Correct |
5 ms |
256 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
256 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
7 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
6 ms |
384 KB |
Output is correct |
40 |
Correct |
6 ms |
384 KB |
Output is correct |