#include "koala.h"
#include <bits/stdc++.h>
const int N = 100;
using namespace std;
int minValue(int N, int W) {
int a[N], b[N];
a[0] = 1;
for(int i = 1; i < N; i++){
a[i] = 0;
}
playRound(a, b);
if(b[0] <= 1){
return 0;
}else{
for(int i = 1; i < N; i++){
if(b[i] == 0){
return i;
}
}
}
}
int getMax(int N, int W, vector<int> v){
int a[N], b[N];
int st = v.size();
while(v.size() != 1){
for(int i = 0; i < N; i++) a[i] = 0;
int k = v.size();
int sq = 0; while((sq + 1) * (sq + 2) / 2 < st) sq++;
for(auto i : v){
a[i] = min(st + W - N - 1, min(W / k, k + W - N + sq - 1));
}
playRound(a, b);
vector<int> nv;
for(int i = 0; i < N; i++){
if(a[i] != 0 && b[i] > a[i]){
nv.push_back(i);
}
}
assert(nv.size() != 0 && v.size() != nv.size());
v = nv;
}
return v[0];
}
int maxValue(int N, int W) {
vector<int> v;
for(int i = 0; i < N; i++)
v.push_back(i);
return getMax(N, W, v);
}
int greaterValue(int N, int W) {
int a[N], b[N];
for(int k : vector<int>{2, 4, 8}){
a[0] = a[1] = k;
for(int i = 2; i < N; i++){
a[i] = 0;
}
playRound(a, b);
if(b[0] == 0 && b[1] == 0){
return minValue(N, W);
}
if(b[0] > k && k >= b[1]){
return 0;
}else if(b[0] <= k && k < b[1]){
return 1;
}
}
}
int C2(int n){
if(n <= 0) return 0;
return n * (n + 1) / 2;
}
void solve(int L, int R, int *P, vector<int>& indexes){
if(L == R){
P[indexes[0]] = L;
return;
}
int S = R - L + 1;
for(int K = 1; ; K++){
if(C2(K + 1 - S) < R && L <= C2((K + 1) * S - S) - C2((K + 1) * (S - 1) - S)){
int a[N], b[N];
for(int i = 0; i < N; i++) a[i] = b[i] = 0;
for(auto i : indexes) a[i] = K;
playRound(a, b);
vector<int> sm, gr;
for(auto i : indexes) {
if(b[i] > K) gr.push_back(i);
else sm.push_back(i);
}
solve(L, L + sm.size() - 1, P, sm);
solve(L + sm.size(), R, P, gr);
break;
}
}
}
void allValues(int N, int W, int *P) {
if(W == N * 2){
vector<int> Q;
vector<int> v;
for(int i = 0; i < N; i++){
v.push_back(i);
}
for(int i = 0; i < N; i++){
int mx = getMax(N, W, v);
Q.push_back(mx);
int idx = 0;
for(int i = 0; i < N; i++){
if(v[i] == mx) idx = i;
}
swap(v[idx], v[(int) v.size() - 1]);
v.resize(N - i - 1);
}
for(int i = 0; i < N; i++){
P[Q[i]] = N - i;
}
}else{
vector<int> indexes;
for(int i = 0; i < N; i++){
indexes.push_back(i);
}
solve(1, N, P, indexes);
}
}
Compilation message
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
23 | }
| ^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
75 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
4 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 |
316 KB |
Output is correct |
2 |
Correct |
13 ms |
208 KB |
Output is correct |
3 |
Correct |
13 ms |
312 KB |
Output is correct |
4 |
Correct |
13 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
292 KB |
Output is correct |
2 |
Correct |
31 ms |
208 KB |
Output is correct |
3 |
Correct |
33 ms |
320 KB |
Output is correct |
4 |
Correct |
32 ms |
316 KB |
Output is correct |
5 |
Correct |
31 ms |
300 KB |
Output is correct |
6 |
Correct |
31 ms |
304 KB |
Output is correct |
7 |
Correct |
32 ms |
316 KB |
Output is correct |
8 |
Correct |
31 ms |
320 KB |
Output is correct |
9 |
Correct |
31 ms |
316 KB |
Output is correct |
10 |
Correct |
40 ms |
316 KB |
Output is correct |
11 |
Correct |
35 ms |
312 KB |
Output is correct |
12 |
Correct |
30 ms |
208 KB |
Output is correct |
13 |
Correct |
31 ms |
208 KB |
Output is correct |
14 |
Correct |
40 ms |
208 KB |
Output is correct |
15 |
Correct |
31 ms |
316 KB |
Output is correct |
16 |
Correct |
30 ms |
316 KB |
Output is correct |
17 |
Correct |
30 ms |
316 KB |
Output is correct |
18 |
Correct |
31 ms |
312 KB |
Output is correct |
19 |
Correct |
31 ms |
316 KB |
Output is correct |
20 |
Correct |
35 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
336 KB |
Output is correct |
17 |
Correct |
3 ms |
208 KB |
Output is correct |
18 |
Correct |
3 ms |
336 KB |
Output is correct |
19 |
Correct |
3 ms |
336 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
336 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
208 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
4 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
324 KB |
Output is correct |
29 |
Correct |
3 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
208 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
208 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
36 |
Correct |
3 ms |
336 KB |
Output is correct |
37 |
Correct |
4 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
4 ms |
208 KB |
Output is correct |
40 |
Correct |
3 ms |
208 KB |
Output is correct |