#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
int moi[MAX_N], adverse[MAX_N], won[MAX_N];
void play() {
playRound(moi, adverse);
for (int i = 0; i < MAX_N; ++i) {
won[i] = (adverse[i] > moi[i]);
}
}
void reset() {
memset(moi, 0, sizeof(moi));
memset(adverse, 0, sizeof(adverse));
memset(won, 0, sizeof(won));
}
int minValue(int N, int W) {
reset();
moi[0] = 1;
play();
for (int i = 0; i < N; ++i) {
if (!won[i]) {
return i;
}
}
}
int maxValue(int N, int W) {
reset();
vector<int> isCand(N, 1);
int cnt = N;
while (cnt > 1) {
reset();
int perPos = N/cnt;
for (int i = 0; i < N; ++i) {
if (isCand[i]) {
moi[i] = perPos;
}
}
play();
cnt = 0;
for (int i = 0; i < N; ++i) {
isCand[i] &= won[i];
cnt += isCand[i];
}
}
int argMax = 0;
while (!isCand[argMax]) ++argMax;
return argMax;
}
bool comp(int N, int W, int i, int j) { // P[i] < P[j]
if (i == j) return false;
if (W == 2*N) {
reset();
moi[i] = moi[j] = N;
play();
return won[j];
} else {
assert(W == N);
reset();
int lo = 1, hi = min(9, W/2);
while (lo <= hi) {
int mid = (lo+hi)/2;
reset();
moi[i] = moi[j] = mid;
play();
if (won[i] < won[j]) return true;
if (won[i] > won[j]) return false;
if (!won[i]) hi = mid-1;
else lo = mid+1;
}
}
}
int greaterValue(int N, int W) {
return (comp(N, W, 0, 1) ? 1 : 0);
}
void allValues(int N, int W, int *P) {
auto Merge = [&] (auto merge, vector<int> A) {
int sz = A.size();
if (sz <= 1) return A;
vector<int> L(A.begin(), A.begin() + sz/2), R(A.begin() + sz/2, A.end());
L = merge(merge, L);
R = merge(merge, R);
A.clear();
reverse(L.begin(), L.end());
reverse(R.begin(), R.end());
while (!L.empty() || !R.empty()) {
auto &take = (R.empty() || (!L.empty() && comp(N, W, L.back(), R.back()))) ? L : R;
A.push_back(take.back());
take.pop_back();
}
return A;
};
vector<int> order(N);
iota(order.begin(), order.end(), 0);
order = Merge(Merge, order);
for (int i = 0; i < N; ++i) {
P[order[i]] = i+1;
}
}
Compilation message
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
29 | }
| ^
koala.cpp: In function 'bool comp(int, int, int, int)':
koala.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
77 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
4 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
208 KB |
Output is correct |
2 |
Correct |
10 ms |
208 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
328 KB |
Output is correct |
2 |
Correct |
48 ms |
320 KB |
Output is correct |
3 |
Correct |
45 ms |
332 KB |
Output is correct |
4 |
Correct |
39 ms |
336 KB |
Output is correct |
5 |
Correct |
41 ms |
456 KB |
Output is correct |
6 |
Correct |
42 ms |
332 KB |
Output is correct |
7 |
Correct |
40 ms |
324 KB |
Output is correct |
8 |
Correct |
53 ms |
336 KB |
Output is correct |
9 |
Correct |
48 ms |
328 KB |
Output is correct |
10 |
Correct |
43 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
300 KB |
Output is correct |
2 |
Correct |
26 ms |
324 KB |
Output is correct |
3 |
Correct |
26 ms |
208 KB |
Output is correct |
4 |
Correct |
25 ms |
324 KB |
Output is correct |
5 |
Correct |
24 ms |
208 KB |
Output is correct |
6 |
Correct |
25 ms |
296 KB |
Output is correct |
7 |
Correct |
24 ms |
208 KB |
Output is correct |
8 |
Correct |
24 ms |
368 KB |
Output is correct |
9 |
Correct |
24 ms |
208 KB |
Output is correct |
10 |
Correct |
24 ms |
316 KB |
Output is correct |
11 |
Correct |
25 ms |
300 KB |
Output is correct |
12 |
Correct |
18 ms |
316 KB |
Output is correct |
13 |
Correct |
24 ms |
320 KB |
Output is correct |
14 |
Correct |
22 ms |
244 KB |
Output is correct |
15 |
Correct |
23 ms |
300 KB |
Output is correct |
16 |
Correct |
22 ms |
316 KB |
Output is correct |
17 |
Correct |
27 ms |
208 KB |
Output is correct |
18 |
Correct |
22 ms |
372 KB |
Output is correct |
19 |
Correct |
22 ms |
208 KB |
Output is correct |
20 |
Correct |
25 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
12 ms |
208 KB |
Output is partially correct |
2 |
Partially correct |
21 ms |
324 KB |
Output is partially correct |
3 |
Partially correct |
21 ms |
208 KB |
Output is partially correct |
4 |
Partially correct |
20 ms |
328 KB |
Output is partially correct |
5 |
Partially correct |
19 ms |
208 KB |
Output is partially correct |
6 |
Partially correct |
21 ms |
320 KB |
Output is partially correct |
7 |
Partially correct |
20 ms |
208 KB |
Output is partially correct |
8 |
Partially correct |
19 ms |
320 KB |
Output is partially correct |
9 |
Partially correct |
25 ms |
320 KB |
Output is partially correct |
10 |
Partially correct |
19 ms |
320 KB |
Output is partially correct |
11 |
Partially correct |
22 ms |
348 KB |
Output is partially correct |
12 |
Partially correct |
17 ms |
208 KB |
Output is partially correct |
13 |
Partially correct |
19 ms |
208 KB |
Output is partially correct |
14 |
Partially correct |
25 ms |
256 KB |
Output is partially correct |
15 |
Partially correct |
25 ms |
320 KB |
Output is partially correct |
16 |
Partially correct |
22 ms |
324 KB |
Output is partially correct |
17 |
Partially correct |
20 ms |
324 KB |
Output is partially correct |
18 |
Partially correct |
19 ms |
208 KB |
Output is partially correct |
19 |
Partially correct |
19 ms |
320 KB |
Output is partially correct |
20 |
Partially correct |
20 ms |
328 KB |
Output is partially correct |
21 |
Partially correct |
20 ms |
376 KB |
Output is partially correct |
22 |
Partially correct |
19 ms |
320 KB |
Output is partially correct |
23 |
Partially correct |
20 ms |
328 KB |
Output is partially correct |
24 |
Partially correct |
19 ms |
320 KB |
Output is partially correct |
25 |
Partially correct |
19 ms |
320 KB |
Output is partially correct |
26 |
Partially correct |
21 ms |
320 KB |
Output is partially correct |
27 |
Partially correct |
19 ms |
208 KB |
Output is partially correct |
28 |
Partially correct |
22 ms |
312 KB |
Output is partially correct |
29 |
Partially correct |
20 ms |
208 KB |
Output is partially correct |
30 |
Partially correct |
19 ms |
208 KB |
Output is partially correct |
31 |
Partially correct |
21 ms |
208 KB |
Output is partially correct |
32 |
Partially correct |
24 ms |
316 KB |
Output is partially correct |
33 |
Partially correct |
20 ms |
256 KB |
Output is partially correct |
34 |
Partially correct |
17 ms |
320 KB |
Output is partially correct |
35 |
Partially correct |
20 ms |
324 KB |
Output is partially correct |
36 |
Partially correct |
18 ms |
324 KB |
Output is partially correct |
37 |
Partially correct |
18 ms |
320 KB |
Output is partially correct |
38 |
Partially correct |
21 ms |
208 KB |
Output is partially correct |
39 |
Partially correct |
18 ms |
320 KB |
Output is partially correct |
40 |
Partially correct |
24 ms |
316 KB |
Output is partially correct |