제출 #1170255

#제출 시각아이디문제언어결과실행 시간메모리
11702558pete8Koala Game (APIO17_koala)C++20
74 / 100
35 ms464 KiB
#include "koala.h" #include<iostream> #include<vector> #include<cassert> using namespace std; #define pb push_back int minValue(int N, int W) { // TODO: Implement Subtask 1 solution here. // You may leave this function unmodified if you are not attempting this // subtask. int B[N],R[N]; for(int i=0;i<N;i++)B[i]=R[i]=0; B[0]=1; playRound(B,R); for(int i=0;i<N;i++)if(R[i]==0)return i; return 0; } int maxValue(int N, int W) { // TODO: Implement Subtask 2 solution here. // You may leave this function unmodified if you are not attempting this // subtask. int B[N],R[N]; for(int i=0;i<N;i++)B[i]=1,R[i]=0; int c=2; for(int j=0;j<10;j++){ playRound(B,R); int x=0,y=0; for(int j=0;j<N;j++){ if(R[j]>1)x++,y=j; } if(x==1)return y; c=(W/x); for(int j=0;j<N;j++){ if(R[j]>1)B[j]=c,x++,y=j; else B[j]=0; } if(x==1)return y; } //5 3 2 1 6 4 return 0; } int greaterValue(int N, int W) { // TODO: Implement Subtask 3 solution here. // You may leave this function unmodified if you are not attempting this // subtask. int B[N],R[N]; int l=1,r=min(9,N/2); while(l<=r){ int mid=l+(r-l)/2; for(int i=0;i<N;i++)R[i]=B[i]=0; B[0]=B[1]=mid; playRound(B,R); if(R[0]==R[1]){ if(R[0]==0)r=mid-1; else l=mid+1; } else return R[0]<R[1]; } return 0; } int n,w; int B[100],R[100]; int p[100]; bool cmp(int a,int b){ for(int i=0;i<n;i++)B[i]=R[i]=0; B[a]=B[b]=61; playRound(B,R); B[a]=B[b]=0; if(R[a]==R[b])assert(0); int x=R[a]<R[b]; R[a]=R[b]=0; return x; } bool cmp2(int a,int b){ int l=1,r=9; while(l<=r){ int mid=l+(r-l)/2; B[a]=B[b]=mid; playRound(B,R); B[a]=B[b]=0; if(R[a]==R[b]){ if(R[a]==0)r=mid-1; else l=mid+1; R[a]=R[b]=0; } else{ int x=(R[a]<R[b]); R[a]=R[b]=0; return x; } } return 0; } void ms(int l,int r){ if(l==r)return; int mid=l+(r-l)/2; ms(l,mid); ms(mid+1,r); vector<int>done; int L=l,R=mid+1; while(L<=mid&&R<=r){ if(cmp(p[L],p[R]))done.pb(p[L++]); else done.pb(p[R++]); } while(L<=mid)done.pb(p[L++]); while(R<=r)done.pb(p[R++]); for(int i=0;i<done.size();i++)p[i+l]=done[i]; } void ms2(int l,int r){ if(l==r)return; int mid=l+(r-l)/2; ms2(l,mid); ms2(mid+1,r); vector<int>done; int L=l,R=mid+1; while(L<=mid&&R<=r){ if(cmp2(p[L],p[R]))done.pb(p[L++]); else done.pb(p[R++]); } while(L<=mid)done.pb(p[L++]); while(R<=r)done.pb(p[R++]); for(int i=0;i<done.size();i++)p[i+l]=done[i]; } void allValues(int N, int W, int *P) { n=N; w=W; for(int i=0;i<n;i++)p[i]=i,B[i]=R[i]=0; if (W == 2*N) { ms(0,n-1); for(int i=0;i<n;i++)P[p[i]]=i+1; // TODO: Implement Subtask 4 solution here. // You may leave this block unmodified if you are not attempting this // subtask. } else { ms2(0,n-1); for(int i=0;i<n;i++)P[p[i]]=i+1; // TODO: Implement Subtask 5 solution here. // You may leave this block unmodified if you are not attempting this // subtask. } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...