#include "koala.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int b[N], r[N], mark[N], ans[N], c[N], order[N];
int n, w;
int minValue(int n, int w) {
for(int i = 0; i < n; i++) b[i] = 0;
b[0] = 1;
playRound(b, r);
for(int i = 0; i < n; i++) if (!r[i]) return i;
return 0;
}
int maxValue(int n, int w) {
for(int i = 0; i < n; i++) mark[i] = 1;
while (1) {
int cnt = 0;
for(int i = 0; i < n; i++) cnt += mark[i];
if (cnt == 1) break;
int val = w / cnt;
for(int i = 0; i < n; i++) {
if (mark[i]) b[i] = val;
else b[i] = 0;
}
playRound(b, r);
for(int i = 0; i < n; i++) mark[i] &= (r[i] > 0);
}
for(int i = 0; i < n; i++) if (mark[i]) return i;
return 0;
}
int greaterValue(int n, int w) {
int L = 1, R = min(w / 2, 9);
while (L <= R) {
int mid = L + R >> 1;
for(int i = 2; i < n; i++) b[i] = 0;
b[0] = b[1] = mid;
playRound(b, r);
int tmp = 0;
for(int i = 0; i < 2; i++) if (r[i] > b[i]) tmp++;
if (tmp == 2) L = mid + 1;
else {
if (tmp == 1) {
if (r[0] > b[0]) return 0;
return 1;
}
R = mid - 1;
}
}
return 0;
}
void solve(vector<int> lst, int L, int R) {
if (lst.size() == 1) {
ans[lst[0]] = L;
return;
}
int l = 1, r = min(10, w / (int)lst.size());
while (l <= r) {
int mid = l + r >> 1;
for(int i = 0; i < n; i++) b[i] = 0;
for(int &j : lst) b[j] = mid;
playRound(b, c);
int tmp = 0;
for(int &j : lst) tmp += (c[j] > b[j]);
if (tmp == lst.size()) l = mid + 1;
else {
if (tmp > 0) {
vector<int> v1, v2;
for(int &j : lst) {
if (c[j] > b[j]) v1.push_back(j);
else v2.push_back(j);
}
solve(v2, L, L + v2.size() - 1);
solve(v1, L + v2.size(), R);
return;
}
else r = mid - 1;
}
}
}
bool cmp(const int &x, const int &y) {
for(int i = 0; i < n; i++) b[i] = 0;
b[x] = w / 2; b[y] = w / 2;
playRound(b, c);
return c[x] <= b[x];
}
void MergeSort(vector<int> &v) {
if (v.size() == 1) return;
vector<int> L, R;
for (int i = 0; i < (int) v.size() / 2; ++i) L.push_back(v[i]);
for (int i = (int) v.size() / 2; i < (int) v.size(); ++i) R.push_back(v[i]);
MergeSort(L); MergeSort(R);
v.clear();
while (L.size() || R.size()) {
if (L.size() && R.size()) {
if (cmp(L[0], R[0])) {
v.push_back(L[0]);
L.erase(L.begin());
}
else {
v.push_back(R[0]);
R.erase(R.begin());
}
}
else if (L.size()) {
v.push_back(L[0]);
L.erase(L.begin());
}
else {
v.push_back(R[0]);
R.erase(R.begin());
}
}
}
void allValues(int _n, int W, int *P) {
n = _n;
w = W;
if (W == 2 * n) {
vector<int> v(n);
iota(v.begin(), v.end(), 0);
MergeSort(v);
for(int i = 0; i < n; i++) P[v[i]] = i + 1;
} else {
vector<int> init;
for(int i = 0; i < n; i++) init.push_back(i);
solve(init, 1, n);
for(int i = 0; i < n; i++) P[i] = ans[i];
}
}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:36:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid = L + R >> 1;
| ~~^~~
koala.cpp: In function 'void solve(std::vector<int>, int, int)':
koala.cpp:62:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | int mid = l + r >> 1;
| ~~^~~
koala.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | if (tmp == lst.size()) l = mid + 1;
| ~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
316 KB |
Output is correct |
3 |
Correct |
4 ms |
208 KB |
Output is correct |
4 |
Correct |
4 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
320 KB |
Output is correct |
2 |
Correct |
14 ms |
316 KB |
Output is correct |
3 |
Correct |
17 ms |
208 KB |
Output is correct |
4 |
Correct |
13 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
324 KB |
Output is correct |
2 |
Correct |
60 ms |
336 KB |
Output is correct |
3 |
Correct |
52 ms |
336 KB |
Output is correct |
4 |
Correct |
49 ms |
340 KB |
Output is correct |
5 |
Correct |
49 ms |
324 KB |
Output is correct |
6 |
Correct |
53 ms |
328 KB |
Output is correct |
7 |
Correct |
60 ms |
328 KB |
Output is correct |
8 |
Correct |
48 ms |
328 KB |
Output is correct |
9 |
Correct |
51 ms |
336 KB |
Output is correct |
10 |
Correct |
47 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
208 KB |
Output is correct |
2 |
Correct |
29 ms |
308 KB |
Output is correct |
3 |
Correct |
38 ms |
208 KB |
Output is correct |
4 |
Correct |
41 ms |
208 KB |
Output is correct |
5 |
Correct |
28 ms |
208 KB |
Output is correct |
6 |
Correct |
30 ms |
208 KB |
Output is correct |
7 |
Correct |
27 ms |
316 KB |
Output is correct |
8 |
Correct |
27 ms |
208 KB |
Output is correct |
9 |
Correct |
28 ms |
320 KB |
Output is correct |
10 |
Correct |
33 ms |
328 KB |
Output is correct |
11 |
Correct |
27 ms |
312 KB |
Output is correct |
12 |
Correct |
18 ms |
208 KB |
Output is correct |
13 |
Correct |
27 ms |
208 KB |
Output is correct |
14 |
Correct |
27 ms |
208 KB |
Output is correct |
15 |
Correct |
27 ms |
308 KB |
Output is correct |
16 |
Correct |
25 ms |
208 KB |
Output is correct |
17 |
Correct |
26 ms |
208 KB |
Output is correct |
18 |
Correct |
34 ms |
316 KB |
Output is correct |
19 |
Correct |
25 ms |
320 KB |
Output is correct |
20 |
Correct |
32 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
3 |
Partially correct |
6 ms |
208 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
5 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
6 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
7 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
8 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
9 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
10 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
11 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
12 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
13 |
Partially correct |
4 ms |
320 KB |
Output is partially correct |
14 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
15 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
16 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
17 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
18 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
19 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
20 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
21 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
22 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
23 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
24 |
Partially correct |
4 ms |
324 KB |
Output is partially correct |
25 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
26 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
27 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
28 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
29 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
30 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
31 |
Partially correct |
4 ms |
324 KB |
Output is partially correct |
32 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
33 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
34 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
35 |
Partially correct |
5 ms |
208 KB |
Output is partially correct |
36 |
Partially correct |
4 ms |
320 KB |
Output is partially correct |
37 |
Partially correct |
6 ms |
208 KB |
Output is partially correct |
38 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
39 |
Partially correct |
5 ms |
320 KB |
Output is partially correct |
40 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |