# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1054513 |
2024-08-12T10:22:38 Z |
ㅇ(#11107) |
Koala Game (APIO17_koala) |
C++14 |
|
50 ms |
596 KB |
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
using pii=array<int,2>;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const int N=105;
int B[N],R[N];
int minValue(int n,int w){
B[0]=1;
playRound(B,R);
for(int i=0;i<n;i++) if(B[i]>=R[i]) return i;
return 0;
}
int maxValue(int n,int w){
vector<int> V;
for(int i=0;i<n;i++) V.push_back(i);
while(V.size()>1){
int m=V.size();
for(int i=0;i<n;i++) B[i]=0;
for(int i: V) B[i]=w/m;
playRound(B,R);
vector<int> NV;
for(int i: V) if(R[i]>B[i]) NV.push_back(i);
V=NV;
}
return V[0];
}
int greaterValue(int n,int w){
int l=1,r=10;
while(l<=r){
int m=(l+r)>>1;
B[0]=B[1]=m;
playRound(B,R);
if(R[0]&&!R[1]) return 0;
if(!R[0]&&R[1]) return 1;
if(R[0]) l=m+1;
else r=m-1;
}
}
int odr[N],to[N][2],m;
vector<int> V[N];
void Do(int n,int p,int q,int W){
for(int i=0;i<n;i++){
if(p<=odr[i]&&odr[i]<=q) B[i]=W;
else B[i]=0;
}
playRound(B,R);
for(int i=1;i<=n;i++) to[i][0]=to[i][1]=0;
for(int i=0;i<n;i++){
if(B[i]<R[i]) to[odr[i]][0]++;
else to[odr[i]][1]++;
}
m=0;
for(int i=1;i<=n;i++){
if(to[i][0]) to[i][0]=++m;
if(to[i][1]) to[i][1]=++m;
}
for(int i=1;i<=n;i++) V[i].clear();
for(int i=0;i<n;i++){
if(B[i]<R[i]) odr[i]=to[odr[i]][0];
else odr[i]=to[odr[i]][1];
V[odr[i]].push_back(i);
}
}
pii sim(int n,int w,int p,int q){
int cnt=0;
for(int i=0;i<n;i++) if(p<=odr[i]&&odr[i]<=q) cnt++;
int m=0,val[N];
for(int i=n;i>=1;i--) for(int x: V[i]) val[x]=++m;
vector<int> X,Y;
for(int i=0;i<n;i++){
if(p<=odr[i]&&odr[i]<=q) X.push_back(i);
else Y.push_back(i);
}
sort(X.begin(),X.end(),[&](int i,int j){
return val[i]>val[j];
});
sort(Y.begin(),Y.end(),[&](int i,int j){
return val[i]>val[j];
});
pii opt{0,-1};
for(int W=1;W<=w/cnt;W++){
int bval=-1,s=0,a=-1,b=-1,c=0;
for(int i=0;i<(int)Y.size();i++) s+=val[Y[i]];
for(int i=-1,j=(int)Y.size()-1;i<(int)X.size();i++){
if((W+1)*(i+1)>w) break;
if(i>=0) s+=val[X[i]];
while((W+1)*(i+1)+(j+1)>w){
s-=val[Y[j]];
j--;
}
if(bval<=s){
if(bval==s) c++;
else c=0;
bval=s;
a=i;
b=j;
}
}
if(c) continue;
for(int i=0;i<n;i++) R[i]=0;
for(int i=0;i<=a;i++) R[X[i]]=B[X[i]]+1;
for(int i=0;i<=b;i++) R[Y[i]]=B[Y[i]]+1;
for(int i=1;i<=n;i++) to[i][0]=to[i][1]=0;
for(int i=0;i<n;i++){
if(B[i]<R[i]) to[odr[i]][0]++;
else to[odr[i]][1]++;
}
int div=0;
for(int i=1;i<=n;i++) if(to[i][0]&&to[i][1]) div+=max(to[i][0],to[i][1]);
if(div>opt[0]){
opt[0]=div;
opt[1]=W;
}
}
return opt;
}
void allValues(int n,int w,int *P){
for(int i=1;i<=n;i++) V[i].clear();
for(int i=0;i<n;i++){
odr[i]=1;
V[1].push_back(i);
}
while(V[n].empty()){
int p=1;
while((int)V[p].size()==1) p++;
int opt=0,val=-1e9,W=0;
for(int q=p;V[q].size();q++){
pii res=sim(n,w,p,q);
if(val<res[0]){
opt=q;
val=res[0];
W=res[1];
}
}
Do(n,p,opt,W);
}
for(int i=0;i<n;i++) P[i]=n+1-odr[i];
}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:43:1: warning: control reaches end of non-void function [-Wreturn-type]
43 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
344 KB |
Output is correct |
3 |
Correct |
8 ms |
452 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
344 KB |
Output is correct |
2 |
Correct |
35 ms |
344 KB |
Output is correct |
3 |
Correct |
49 ms |
464 KB |
Output is correct |
4 |
Correct |
32 ms |
344 KB |
Output is correct |
5 |
Correct |
31 ms |
344 KB |
Output is correct |
6 |
Correct |
46 ms |
468 KB |
Output is correct |
7 |
Correct |
50 ms |
460 KB |
Output is correct |
8 |
Correct |
31 ms |
468 KB |
Output is correct |
9 |
Correct |
33 ms |
344 KB |
Output is correct |
10 |
Correct |
30 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
23 ms |
344 KB |
Output is correct |
4 |
Correct |
24 ms |
344 KB |
Output is correct |
5 |
Correct |
24 ms |
344 KB |
Output is correct |
6 |
Correct |
42 ms |
344 KB |
Output is correct |
7 |
Correct |
26 ms |
344 KB |
Output is correct |
8 |
Correct |
23 ms |
460 KB |
Output is correct |
9 |
Correct |
23 ms |
344 KB |
Output is correct |
10 |
Correct |
25 ms |
460 KB |
Output is correct |
11 |
Correct |
24 ms |
344 KB |
Output is correct |
12 |
Correct |
19 ms |
344 KB |
Output is correct |
13 |
Correct |
25 ms |
460 KB |
Output is correct |
14 |
Correct |
21 ms |
344 KB |
Output is correct |
15 |
Correct |
35 ms |
344 KB |
Output is correct |
16 |
Correct |
26 ms |
596 KB |
Output is correct |
17 |
Correct |
21 ms |
344 KB |
Output is correct |
18 |
Correct |
21 ms |
464 KB |
Output is correct |
19 |
Correct |
21 ms |
344 KB |
Output is correct |
20 |
Correct |
21 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
21 ms |
456 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
5 |
Correct |
19 ms |
344 KB |
Output is correct |
6 |
Correct |
14 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
460 KB |
Output is correct |
8 |
Correct |
13 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
460 KB |
Output is correct |
10 |
Correct |
13 ms |
344 KB |
Output is correct |
11 |
Correct |
13 ms |
456 KB |
Output is correct |
12 |
Correct |
15 ms |
460 KB |
Output is correct |
13 |
Correct |
12 ms |
464 KB |
Output is correct |
14 |
Correct |
12 ms |
456 KB |
Output is correct |
15 |
Correct |
17 ms |
460 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
19 ms |
460 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
12 ms |
344 KB |
Output is correct |
20 |
Correct |
13 ms |
464 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
15 ms |
344 KB |
Output is correct |
23 |
Correct |
10 ms |
344 KB |
Output is correct |
24 |
Correct |
12 ms |
464 KB |
Output is correct |
25 |
Correct |
13 ms |
344 KB |
Output is correct |
26 |
Correct |
13 ms |
344 KB |
Output is correct |
27 |
Correct |
13 ms |
344 KB |
Output is correct |
28 |
Correct |
13 ms |
344 KB |
Output is correct |
29 |
Correct |
12 ms |
460 KB |
Output is correct |
30 |
Correct |
13 ms |
344 KB |
Output is correct |
31 |
Correct |
13 ms |
460 KB |
Output is correct |
32 |
Correct |
12 ms |
344 KB |
Output is correct |
33 |
Correct |
14 ms |
456 KB |
Output is correct |
34 |
Correct |
10 ms |
344 KB |
Output is correct |
35 |
Correct |
13 ms |
344 KB |
Output is correct |
36 |
Correct |
10 ms |
464 KB |
Output is correct |
37 |
Correct |
11 ms |
344 KB |
Output is correct |
38 |
Correct |
11 ms |
344 KB |
Output is correct |
39 |
Correct |
11 ms |
456 KB |
Output is correct |
40 |
Correct |
11 ms |
344 KB |
Output is correct |