#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
int B[MAXN], R[MAXN];
void Reset() {
for (int i = 0; i < MAXN; i++) {
B[i] = R[i] = 0;
}
}
int minValue(int N, int W) {
Reset();
B[0] = 1;
playRound(B, R);
for (int i = 0; i < N; i++) {
if (R[i] == 0) {
return i;
}
}
return 0;
}
int maxValue(int N, int W) {
vector<int> large(N);
iota(begin(large), end(large), 0);
while (large.size() > 1) {
int k = W / (int) large.size();
Reset();
for (auto i : large) {
B[i] = k;
}
playRound(B, R);
large.clear();
for (int i = 0; i < N; i++) {
if (R[i] > k) {
large.emplace_back(i);
}
}
}
return large[0];
}
int greaterValue(int N, int W) {
int lo = 1, hi = 9;
while (lo <= hi) {
int k = (lo + hi) / 2;
Reset();
B[0] = B[1] = k;
playRound(B, R);
if (R[0] <= k && R[1] <= k) {
hi = k - 1;
} else if (R[0] > k && R[1] > k) {
lo = k + 1;
} else {
return R[0] < R[1];
}
}
return -1;
}
void Solve(int N, int W, int *P, vector<int> v, int l, int r) {
if (l > r) return;
if (l == r) return void(P[v[0]] = l);
int k = min({(int) sqrt(2 * l), W / (r - l + 1), 8});
Reset();
for (auto i : v) {
B[i] = k;
}
playRound(B, R);
vector<int> ls, gr;
for (auto i : v) {
if (R[i] > k) {
gr.emplace_back(i);
} else {
ls.emplace_back(i);
}
}
Solve(N, W, P, ls, l, l + int(ls.size()) - 1);
Solve(N, W, P, gr, r - int(gr.size()) + 1, r);
}
void allValues(int N, int W, int *P) {
if (W == 2 * N) {
vector<int> v(N);
iota(begin(v), end(v), 0);
stable_sort(begin(v), end(v), [&](int a, int b) {
Reset();
B[a] = B[b] = N;
playRound(B, R);
return R[a] < R[b];
});
for (int i = 0; i < N; i++) {
P[v[i]] = i + 1;
}
} else {
vector<int> v(N);
iota(begin(v), end(v), 0);
return Solve(N, W, P, v, 1, N);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
384 KB |
Output is correct |
4 |
Correct |
10 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
384 KB |
Output is correct |
2 |
Correct |
22 ms |
384 KB |
Output is correct |
3 |
Correct |
22 ms |
384 KB |
Output is correct |
4 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
488 KB |
Output is correct |
2 |
Correct |
92 ms |
384 KB |
Output is correct |
3 |
Correct |
80 ms |
384 KB |
Output is correct |
4 |
Correct |
72 ms |
384 KB |
Output is correct |
5 |
Correct |
75 ms |
384 KB |
Output is correct |
6 |
Correct |
76 ms |
384 KB |
Output is correct |
7 |
Correct |
75 ms |
384 KB |
Output is correct |
8 |
Correct |
76 ms |
384 KB |
Output is correct |
9 |
Correct |
78 ms |
384 KB |
Output is correct |
10 |
Correct |
77 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
384 KB |
Output is correct |
2 |
Correct |
53 ms |
376 KB |
Output is correct |
3 |
Correct |
54 ms |
384 KB |
Output is correct |
4 |
Correct |
53 ms |
384 KB |
Output is correct |
5 |
Correct |
52 ms |
384 KB |
Output is correct |
6 |
Correct |
52 ms |
384 KB |
Output is correct |
7 |
Correct |
52 ms |
384 KB |
Output is correct |
8 |
Correct |
52 ms |
504 KB |
Output is correct |
9 |
Correct |
54 ms |
288 KB |
Output is correct |
10 |
Correct |
52 ms |
384 KB |
Output is correct |
11 |
Correct |
53 ms |
504 KB |
Output is correct |
12 |
Correct |
25 ms |
384 KB |
Output is correct |
13 |
Correct |
50 ms |
384 KB |
Output is correct |
14 |
Correct |
46 ms |
504 KB |
Output is correct |
15 |
Correct |
47 ms |
384 KB |
Output is correct |
16 |
Correct |
48 ms |
376 KB |
Output is correct |
17 |
Correct |
47 ms |
376 KB |
Output is correct |
18 |
Correct |
47 ms |
384 KB |
Output is correct |
19 |
Correct |
48 ms |
392 KB |
Output is correct |
20 |
Correct |
48 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
384 KB |
Output is correct |
4 |
Correct |
9 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
6 |
Correct |
8 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
384 KB |
Output is correct |
8 |
Correct |
8 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
384 KB |
Output is correct |
10 |
Correct |
8 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
384 KB |
Output is correct |
17 |
Correct |
8 ms |
384 KB |
Output is correct |
18 |
Correct |
9 ms |
432 KB |
Output is correct |
19 |
Correct |
8 ms |
384 KB |
Output is correct |
20 |
Correct |
8 ms |
384 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
9 ms |
384 KB |
Output is correct |
23 |
Correct |
8 ms |
384 KB |
Output is correct |
24 |
Correct |
8 ms |
384 KB |
Output is correct |
25 |
Correct |
9 ms |
384 KB |
Output is correct |
26 |
Correct |
9 ms |
384 KB |
Output is correct |
27 |
Correct |
8 ms |
384 KB |
Output is correct |
28 |
Correct |
8 ms |
384 KB |
Output is correct |
29 |
Correct |
8 ms |
384 KB |
Output is correct |
30 |
Correct |
8 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
384 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
33 |
Correct |
9 ms |
384 KB |
Output is correct |
34 |
Correct |
8 ms |
384 KB |
Output is correct |
35 |
Correct |
9 ms |
384 KB |
Output is correct |
36 |
Correct |
8 ms |
384 KB |
Output is correct |
37 |
Correct |
9 ms |
384 KB |
Output is correct |
38 |
Correct |
9 ms |
384 KB |
Output is correct |
39 |
Correct |
10 ms |
384 KB |
Output is correct |
40 |
Correct |
8 ms |
384 KB |
Output is correct |