This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
int t;
int minValue(int N, int W) {
int ans=0;
int B[N];
int R[N];
memset(B,0,sizeof(B));
memset(R,0,sizeof(R));
B[0]=1;
playRound(B,R);
for(int i=1;i<N;i++)if(R[i]==0)ans=i;
return ans;
}
int maxValue(int N, int W) {
int l=1,r=13,ans;
int B[N];
int R[N];
bool me[N];
int cnt=1;
memset(B,0,sizeof(B));
memset(me,1,sizeof(me));
while(1){
memset(B,0,sizeof(B));
for(int i=0;i<N;i++){
if(me[i]){
B[i]=cnt;
}
}
playRound(B, R);
int u=0;
for(int i=0;i<N;i++){
if(me[i]&&R[i]>cnt){
u++;
me[i]=1;
}
else me[i]=0;
}
cnt=W/u;
cnt=min(cnt,13);
if(u==1){
for(int i=0;i<N;i++){
if(me[i])return i;
}
}
}
}
int greaterValue(int N, int W) {
int l=1,r=13,ans;
int B[N];
int R[N];
memset(B,0,sizeof(B));
while(l<=r){
int mid=(l+r)/2;
B[0]=mid;
B[1]=mid;
playRound(B, R);
int a=R[0]>mid;
int b=R[1]>mid;
if(a>b)return 0;
if(b>a)return 1;
if(a){
l=mid+1;
}
else r=mid-1;
}
assert(0);
}
bool com(int a,int b)
{
int l=1,r=13,ans;
int B[100];
int R[100];
while(l<=r){
memset(B,0,sizeof(B));
int mid=(l+r)/2;
B[a]=mid;
B[b]=mid;
playRound(B, R);
int u=R[a]>mid;
int v=R[b]>mid;
if(u>v)return 0;
if(v>u)return 1;
if(u){
l=mid+1;
}
else r=mid-1;
}
assert(0);
}
bool com2(int a,int b)
{
int l=1,r=113,ans;
int B[100];
int R[100];
while(l<=r){
memset(B,0,sizeof(B));
int mid=(l+r)/2;
B[a]=mid;
B[b]=mid;
t++;
if(t==701)assert(0);
playRound(B, R);
int u=R[a]>mid;
int v=R[b]>mid;
if(u>v)return 0;
if(v>u)return 1;
if(u){
l=mid+1;
}
else r=mid-1;
}
assert(0);
}
void allValues(int N, int W, int *P) {
if (W == 2*N) {
t=0;
int a[N];
for(int i=0;i<N;i++)a[i]=i;
vector<int> vec[N*3];
int ann=0;
int B[N];
int R[N];
memset(B,0,sizeof(B));
memset(R,0,sizeof(R));
B[0]=1+100;
t++;
playRound(B,R);
for(int i=1;i<N;i++)if(R[i]==0)ann=i;
vec[101].push_back(ann);
for(int i=0;i<N;i++){
if(i==ann)continue;
int l=102,r=113,ans=101;
while(l<=r){
memset(B,0,sizeof(B));
int mid=(l+r)/2;
B[i]=mid;
t++;
if(t==701)assert(0);
playRound(B,R);
if(R[i]>mid){
l=mid+1;
ans=mid;
}
else{
r=mid-1;
}
}
vec[ans].push_back(i);
}
int l=0,cnt=0;
for(int i=1;i<=200;i++){
for(auto x:vec[i]){
a[cnt++]=x;
}
if(abs(cnt-l)>1)sort(a+l,a+cnt,com2);
l=cnt;
}
for(int i=0;i<N;i++){
P[a[i]]=i+1;
}
}
else {
int a[N];
for(int i=0;i<N;i++)a[i]=i;
vector<int> vec[N*3];
int ann=0;
int B[N];
int R[N];
memset(B,0,sizeof(B));
memset(R,0,sizeof(R));
B[0]=1;
playRound(B,R);
for(int i=1;i<N;i++)if(R[i]==0)ann=i;
vec[1].push_back(ann);
for(int i=0;i<N;i++){
if(i==ann)continue;
int l=2,r=13,ans=1;
while(l<=r){
memset(B,0,sizeof(B));
int mid=(l+r)/2;
B[i]=mid;
playRound(B,R);
if(R[i]>mid){
l=mid+1;
ans=mid;
}
else{
r=mid-1;
}
}
vec[ans].push_back(i);
}
int l=0,cnt=0;
for(int i=1;i<14;i++){
for(auto x:vec[i]){
a[cnt++]=x;
}
if(abs(cnt-l)>1)sort(a+l,a+cnt,com);
l=cnt;
}
for(int i=0;i<N;i++){
P[a[i]]=i+1;
}
}
}
/*
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
*/
Compilation message (stderr)
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:21:9: warning: unused variable 'l' [-Wunused-variable]
21 | int l=1,r=13,ans;
| ^
koala.cpp:21:13: warning: unused variable 'r' [-Wunused-variable]
21 | int l=1,r=13,ans;
| ^
koala.cpp:21:18: warning: unused variable 'ans' [-Wunused-variable]
21 | int l=1,r=13,ans;
| ^~~
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:55:18: warning: unused variable 'ans' [-Wunused-variable]
55 | int l=1,r=13,ans;
| ^~~
koala.cpp: In function 'bool com(int, int)':
koala.cpp:77:18: warning: unused variable 'ans' [-Wunused-variable]
77 | int l=1,r=13,ans;
| ^~~
koala.cpp: In function 'bool com2(int, int)':
koala.cpp:99:19: warning: unused variable 'ans' [-Wunused-variable]
99 | int l=1,r=113,ans;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |