답안 #63633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63633 2018-08-02T09:51:56 Z jangwonyoung 코알라 (APIO17_koala) C++14
100 / 100
105 ms 852 KB
#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){
	if(l>r) return 0;
	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;
		}
	}
	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]>v) cnt++;
	}
	for(int i=0; i<n ;i++){
		if(mi[i]!=l) continue;
		if(R[i]>v) 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);
}
bool cmp(int x,int y){
	for(int i=0; i<n ;i++) B[i]=0;
	B[x]=B[y]=100;
	playRound(B,R);
	return (R[y]>100);
}
void allValues(int N, int W, int *P) {
	init();
    if (W == 2*N) {
	    for(int i=0; i<100 ;i++) ma[i]=i;
	    stable_sort(ma,ma+100,cmp);
	    for(int i=0; i<100 ;i++) P[ma[i]]=i+1;
    } else {
        solve(1,n);
        for(int i=0; i<n ;i++) P[i]=mi[i];
    }
}

Compilation message

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 248 KB Output is correct
2 Correct 8 ms 356 KB Output is correct
3 Correct 7 ms 448 KB Output is correct
4 Correct 7 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 540 KB Output is correct
2 Correct 20 ms 540 KB Output is correct
3 Correct 21 ms 540 KB Output is correct
4 Correct 20 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 684 KB Output is correct
2 Correct 70 ms 684 KB Output is correct
3 Correct 76 ms 816 KB Output is correct
4 Correct 77 ms 816 KB Output is correct
5 Correct 73 ms 816 KB Output is correct
6 Correct 93 ms 816 KB Output is correct
7 Correct 105 ms 816 KB Output is correct
8 Correct 87 ms 852 KB Output is correct
9 Correct 81 ms 852 KB Output is correct
10 Correct 83 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 852 KB Output is correct
2 Correct 45 ms 852 KB Output is correct
3 Correct 55 ms 852 KB Output is correct
4 Correct 42 ms 852 KB Output is correct
5 Correct 44 ms 852 KB Output is correct
6 Correct 51 ms 852 KB Output is correct
7 Correct 45 ms 852 KB Output is correct
8 Correct 40 ms 852 KB Output is correct
9 Correct 47 ms 852 KB Output is correct
10 Correct 42 ms 852 KB Output is correct
11 Correct 63 ms 852 KB Output is correct
12 Correct 19 ms 852 KB Output is correct
13 Correct 44 ms 852 KB Output is correct
14 Correct 57 ms 852 KB Output is correct
15 Correct 37 ms 852 KB Output is correct
16 Correct 38 ms 852 KB Output is correct
17 Correct 39 ms 852 KB Output is correct
18 Correct 40 ms 852 KB Output is correct
19 Correct 47 ms 852 KB Output is correct
20 Correct 53 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 852 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 9 ms 852 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 8 ms 852 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 8 ms 852 KB Output is correct
10 Correct 8 ms 852 KB Output is correct
11 Correct 6 ms 852 KB Output is correct
12 Correct 6 ms 852 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 9 ms 852 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 9 ms 852 KB Output is correct
18 Correct 7 ms 852 KB Output is correct
19 Correct 7 ms 852 KB Output is correct
20 Correct 6 ms 852 KB Output is correct
21 Correct 7 ms 852 KB Output is correct
22 Correct 6 ms 852 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 6 ms 852 KB Output is correct
25 Correct 7 ms 852 KB Output is correct
26 Correct 6 ms 852 KB Output is correct
27 Correct 9 ms 852 KB Output is correct
28 Correct 6 ms 852 KB Output is correct
29 Correct 7 ms 852 KB Output is correct
30 Correct 7 ms 852 KB Output is correct
31 Correct 7 ms 852 KB Output is correct
32 Correct 7 ms 852 KB Output is correct
33 Correct 6 ms 852 KB Output is correct
34 Correct 6 ms 852 KB Output is correct
35 Correct 6 ms 852 KB Output is correct
36 Correct 7 ms 852 KB Output is correct
37 Correct 6 ms 852 KB Output is correct
38 Correct 6 ms 852 KB Output is correct
39 Correct 7 ms 852 KB Output is correct
40 Correct 6 ms 852 KB Output is correct