#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int qa[MAXN], ra[MAXN], cmpa[MAXN][MAXN];
int minValue(int N, int W){ // N = 100, W = 100, 2 times
qa[0] = 1;
for (int i = 1; i < N; i++) qa[i] = 0;
playRound(qa, ra);
if (ra[0] <= 1) return 0;
for (int i = 1; i < N; i++)
if (ra[i] == 0)
return i;
}
int maxValue(int N, int W){ // N = 100, W = 100, 4 times
vector<int> loc;
for (int i = 0; i < N; i++) loc.push_back(i);
while (loc.size() > 1){ // 100, 50, 25, 9, 1
int amt = W / loc.size();
for (int i = 0; i < N; i++) qa[i] = 0;
for (int x : loc) qa[x] = amt;
playRound(qa, ra);
vector<int> ori; swap(ori, loc);
for (int x : ori)
if (ra[x] > amt)
loc.push_back(x);
}
return loc[0];
}
int greaterValue(int N, int W){ // N = 100, W = 100, 3 times
for (int i = 0; i < N; i++) qa[i] = 0;
int lo = 0, hi = 4;
int amt[] = {1, 2, 4, 6, 8};
while (lo <= hi){
int m = (lo + hi) >> 1;
qa[0] = qa[1] = amt[m];
playRound(qa, ra);
if (ra[0] > amt[m] != ra[1] > amt[m]) return ra[1] > amt[m];
else if (ra[0] > amt[m]) lo = m + 1;
else hi = m - 1;
}
}
void dnc(int l, int r, vector<int> &vind, int *P){
if (l == r){
P[vind[0]] = l;
return;
}
int sz = r - l + 1, lo = 1, hi = 100 / sz, sh = -1;
vector<int> rem;
for (int i = 1; i < l; i++) rem.push_back(i);
for (int i = r + 1; i <= 100; i++) rem.push_back(i);
while (lo <= hi){
int m = (lo + hi) >> 1, stone = sz, ind = 0, choose = 0;
for (int x = r; x >= l; x--){
int sum = 0;
for (int i = 0; i <= m; i++){
if (stone) stone--;
else if (ind != rem.size()){
sum += rem[ind]; ind++;
}
else{
sum = 1e9; break;
}
}
if (sum > x) break;
else if (sum == x){
if (choose) choose++;
break;
}
else choose++;
}
if (choose == 0) hi = m - 1;
else if (choose == sz) lo = m + 1;
else{
sh = m;
break;
}
}
vector<int> lv, rv;
for (int i = 0; i < 100; i++) qa[i] = 0;
for (int x : vind) qa[x] = sh;
playRound(qa, ra);
for (int x : vind){
if (ra[x] > sh) rv.push_back(x);
else lv.push_back(x);
}
dnc(l, l + lv.size() - 1, lv, P); dnc(l + lv.size(), r, rv, P);
}
bool cmp(int a, int b){
if (cmpa[a][b] != -1) return cmpa[a][b];
qa[a] = qa[b] = 100;
playRound(qa, ra);
qa[a] = qa[b] = 0;
cmpa[a][b] = ra[b] > 100; cmpa[b][a] = 1 - cmpa[a][b];
return cmpa[a][b];
}
void allValues(int N, int W, int *P){
if (W == 100){ // N = 100, W = 100, 100 times
vector<int> vind(100);
for (int i = 0; i < 100; i++) vind[i] = i;
dnc(1, 100, vind, P);
}
else{ // N = 100, W = 200, 700 times
memset(cmpa, -1, sizeof(cmpa));
for (int i = 0; i < 100; i++) qa[i] = 0;
vector<int> ord(100);
for (int i = 0; i < 100; i++) ord[i] = i;
stable_sort(ord.begin(), ord.end(), cmp);
for (int i = 0; i < 100; i++) P[ord[i]] = i + 1;
}
}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:42:13: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
42 | if (ra[0] > amt[m] != ra[1] > amt[m]) return ra[1] > amt[m];
| ~~~~~~^~~~~~~~
koala.cpp: In function 'void dnc(int, int, std::vector<int>&, int*)':
koala.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | else if (ind != rem.size()){
| ~~~~^~~~~~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
16 | }
| ^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
46 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
464 KB |
Output is correct |
2 |
Correct |
57 ms |
484 KB |
Output is correct |
3 |
Correct |
50 ms |
468 KB |
Output is correct |
4 |
Correct |
47 ms |
484 KB |
Output is correct |
5 |
Correct |
47 ms |
460 KB |
Output is correct |
6 |
Correct |
48 ms |
476 KB |
Output is correct |
7 |
Correct |
49 ms |
472 KB |
Output is correct |
8 |
Correct |
49 ms |
500 KB |
Output is correct |
9 |
Correct |
47 ms |
476 KB |
Output is correct |
10 |
Correct |
52 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
756 KB |
Output is correct |
2 |
Correct |
29 ms |
488 KB |
Output is correct |
3 |
Correct |
27 ms |
340 KB |
Output is correct |
4 |
Correct |
27 ms |
344 KB |
Output is correct |
5 |
Correct |
26 ms |
344 KB |
Output is correct |
6 |
Correct |
26 ms |
344 KB |
Output is correct |
7 |
Correct |
26 ms |
500 KB |
Output is correct |
8 |
Correct |
27 ms |
596 KB |
Output is correct |
9 |
Correct |
26 ms |
488 KB |
Output is correct |
10 |
Correct |
25 ms |
344 KB |
Output is correct |
11 |
Correct |
27 ms |
344 KB |
Output is correct |
12 |
Correct |
12 ms |
492 KB |
Output is correct |
13 |
Correct |
25 ms |
344 KB |
Output is correct |
14 |
Correct |
23 ms |
344 KB |
Output is correct |
15 |
Correct |
23 ms |
344 KB |
Output is correct |
16 |
Correct |
24 ms |
344 KB |
Output is correct |
17 |
Correct |
23 ms |
344 KB |
Output is correct |
18 |
Correct |
24 ms |
344 KB |
Output is correct |
19 |
Correct |
24 ms |
484 KB |
Output is correct |
20 |
Correct |
24 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
3 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
428 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
3 ms |
344 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
3 ms |
344 KB |
Output is correct |
31 |
Correct |
3 ms |
344 KB |
Output is correct |
32 |
Correct |
3 ms |
344 KB |
Output is correct |
33 |
Correct |
3 ms |
344 KB |
Output is correct |
34 |
Correct |
3 ms |
344 KB |
Output is correct |
35 |
Correct |
3 ms |
344 KB |
Output is correct |
36 |
Correct |
3 ms |
344 KB |
Output is correct |
37 |
Correct |
3 ms |
344 KB |
Output is correct |
38 |
Correct |
3 ms |
344 KB |
Output is correct |
39 |
Correct |
3 ms |
344 KB |
Output is correct |
40 |
Correct |
3 ms |
344 KB |
Output is correct |