#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, int from, int to) {
if (lst.size() == 1) {
ans[lst[0]] = L;
return;
}
int l = from, r = min(to, 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, from, mid);
solve(v1, L + v2.size(), R, mid, to);
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();
int i = 0, j = 0;
while (i < (int) L.size() || j < (int) R.size()) {
if (i < (int) L.size() && j < (int) R.size()) {
if (cmp(L[i], R[j])) v.push_back(L[i++]);
else v.push_back(R[j++]);
}
else if (i < (int) L.size()) v.push_back(L[i++]);
else v.push_back(R[j++]);
}
}
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, 1, 9);
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, 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 |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
208 KB |
Output is correct |
2 |
Correct |
14 ms |
208 KB |
Output is correct |
3 |
Correct |
12 ms |
208 KB |
Output is correct |
4 |
Correct |
12 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
328 KB |
Output is correct |
2 |
Correct |
80 ms |
316 KB |
Output is correct |
3 |
Correct |
64 ms |
336 KB |
Output is correct |
4 |
Correct |
51 ms |
328 KB |
Output is correct |
5 |
Correct |
50 ms |
332 KB |
Output is correct |
6 |
Correct |
51 ms |
328 KB |
Output is correct |
7 |
Correct |
49 ms |
336 KB |
Output is correct |
8 |
Correct |
71 ms |
332 KB |
Output is correct |
9 |
Correct |
56 ms |
324 KB |
Output is correct |
10 |
Correct |
49 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
320 KB |
Output is correct |
2 |
Correct |
29 ms |
208 KB |
Output is correct |
3 |
Correct |
33 ms |
312 KB |
Output is correct |
4 |
Correct |
37 ms |
208 KB |
Output is correct |
5 |
Correct |
31 ms |
208 KB |
Output is correct |
6 |
Correct |
29 ms |
320 KB |
Output is correct |
7 |
Correct |
38 ms |
208 KB |
Output is correct |
8 |
Correct |
30 ms |
300 KB |
Output is correct |
9 |
Correct |
28 ms |
320 KB |
Output is correct |
10 |
Correct |
29 ms |
208 KB |
Output is correct |
11 |
Correct |
28 ms |
320 KB |
Output is correct |
12 |
Correct |
19 ms |
320 KB |
Output is correct |
13 |
Correct |
38 ms |
300 KB |
Output is correct |
14 |
Correct |
26 ms |
316 KB |
Output is correct |
15 |
Correct |
27 ms |
316 KB |
Output is correct |
16 |
Correct |
26 ms |
208 KB |
Output is correct |
17 |
Correct |
24 ms |
324 KB |
Output is correct |
18 |
Correct |
26 ms |
316 KB |
Output is correct |
19 |
Correct |
29 ms |
208 KB |
Output is correct |
20 |
Correct |
32 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |