#include "koala.h"
#include<iostream>
#include<algorithm>
#include<cassert>
using namespace std;
int B[100],R[100];
int mi[100],ma[100];
int n=100;
void init(){
for(int i=0; i<n ;i++) B[i]=0,mi[i]=1,ma[i]=100;
}
int sum(int l,int r){
return (r+l)*(r-l+1)/2;
}
int f(int l,int r,int w){
int minv=r-l+1;
int ans=0;
for(int i=0; i<=w/(r-l+1) ;i++){
int val=sum(1,n)-sum(l,r);
int best=0;
for(int j=1; j<=r-l+1 ;j++){
if((i+1)*j+n-r>w) break;
int cv=sum(r+1,n)+sum(r-j+1,r)+sum(max(1,l-(w-((i+1)*j+n-r))),l-1);
if(cv>val || cv>=val && best!=0){
val=cv;
best=j;
}
}
if(best!=0 && best<minv){
minv=best;
ans=i;
}
}
assert(minv!=0);
assert(minv!=r-l+1);
return ans;
}
int play(int l,int r,int v){
for(int i=0; i<n ;i++){
if(mi[i]!=l) B[i]=0;
else B[i]=v;
}
playRound(B,R);
int cnt=0;
for(int i=0; i<n ;i++){
if(mi[i]!=l) continue;
if(R[i]!=0) cnt++;
}
for(int i=0; i<n ;i++){
if(mi[i]!=l) continue;
if(R[i]!=0) mi[i]=r-cnt+1;
else ma[i]=r-cnt;
}
return cnt;
}
int minValue(int N, int W) {
init();
B[0]=1;
playRound(B,R);
for(int i=0; i<n ;i++) if(R[i]==0) return i;
}
int maxValue(int N, int W) {
init();
int l=1,r=n;
while(l!=n){
l=r-play(l,r,f(l,r,W))+1;
}
for(int i=0; i<n ;i++) if(mi[i]==n) return i;
}
int greaterValue(int N, int W) {
init();
B[0]=B[1]=4;
playRound(B,R);
if(R[0]!=R[1]) return (R[0]==0);
if(R[0]==0){
B[0]=B[1]=2;
playRound(B,R);
if(R[0]!=R[1]) return (R[0]==0);
B[0]=B[1]=1;
playRound(B,R);
if(R[0]!=R[1]) return (R[0]==0);
}
else{
B[0]=B[1]=8;
playRound(B,R);
if(R[0]!=R[1]) return (R[0]==0);
}
return 0;
}
void solve(int l,int r){
if(l==r) return;
int num=play(l,r,f(l,r,100));
solve(l,r-num);
solve(r-num+1,r);
}
void allValues(int N, int W, int *P) {
init();
if (W == 2*N) {
// TODO: Implement Subtask 4 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
} else {
while(true);
solve(1,n);
for(int i=0; i<n ;i++) P[i]=mi[i];
}
}
Compilation message
koala.cpp: In function 'int f(int, int, int)':
koala.cpp:24:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(cv>val || cv>=val && best!=0){
~~~~~~~~^~~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
368 KB |
Output is correct |
2 |
Correct |
7 ms |
368 KB |
Output is correct |
3 |
Correct |
7 ms |
580 KB |
Output is correct |
4 |
Correct |
7 ms |
580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
648 KB |
Output is correct |
2 |
Correct |
18 ms |
648 KB |
Output is correct |
3 |
Correct |
28 ms |
648 KB |
Output is correct |
4 |
Correct |
20 ms |
744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
744 KB |
Output is correct |
2 |
Correct |
103 ms |
744 KB |
Output is correct |
3 |
Correct |
73 ms |
744 KB |
Output is correct |
4 |
Correct |
77 ms |
744 KB |
Output is correct |
5 |
Correct |
71 ms |
744 KB |
Output is correct |
6 |
Correct |
80 ms |
744 KB |
Output is correct |
7 |
Correct |
120 ms |
744 KB |
Output is correct |
8 |
Correct |
86 ms |
744 KB |
Output is correct |
9 |
Correct |
79 ms |
808 KB |
Output is correct |
10 |
Correct |
71 ms |
808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |