# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
107364 | oolimry | 코알라 (APIO17_koala) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
void playRound(int *B, int *R);
//#include "koala.h"
#include<bits/stdc++.h>
using namespace std;
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];
int R[N];
fill(B,B+N,0);
fill(R,R+N,0);
B[0] = 1;
playRound(B,R);
for(int i = 0;i < N;i++){
if(R[i] == 0) return i;
}
/*
B[0] = 0;
B[1] = 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) {
int B1[N], B2[N], B3[N], B4[N];
int R1[N], R2[N], R3[N], R4[N];
for(int i = 0;i < N;i++){
B1[i] = 1;
}
playRound(B1,R1);
for(int i = 0;i < N;i++){
B2[i] = R1[i];
}
playRound(B2,R2);
for(int i = 0;i < N;i++){
//printf("%d ",R2[i]);
if(R2[i] == 3) B3[i] = 4;
else B3[i] = 0;
}
playRound(B3,R3);
for(int i = 0;i < N;i++){
//printf("%d ",R3[i]);
if(R3[i] == 5) B4[i] = 11;
else B4[i] = 0;
}
playRound(B4,R4);
for(int i = 0;i < N;i++){
//printf("%d ",R4[i]);
if(R4[i] == 12) return i;
}
return 0;
}
int greaterValue(int N, int W) {
int B[N];
int R[N];
fill(B,B+N,0);
B[0] = 1;
B[1] = 1;
playRound(B,R);
if(R[0] == 0 && R[1] > 0) return 1; ///something stands out
else if(R[0] > 0 && R[1] == 0) return 0; ///something stands out
else if(R[0] == 0 && R[1] == 0){ ///The numbers are at most 5
fill(B,B+N,0);
B[0] = 1;
B[1] = 1;
playRound(B,R);
}
return 0;
}
void allValues(int N, int W, int *P) {
if (W == 2*N) {
// TODO: Implement Subtask 4 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
} else {
// TODO: Implement Subtask 5 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
}
}
static int N, W;
static int P[105];
static int maxQueries = 3200;
static int numQueries;
static void runGame(int F);
static void grader();
int main() {
freopen("i.txt","r",stdin);
//for(int i = 0;i < 100;i++){
// printf("%d ",i+1);
//}
grader();
return 0;
}
void playRound(int *B, int *R) {
int i, j;
int S = 0;
for (i=0;i<N;++i) {
if ( !(B[i] >= 0 && B[i] <= W) ) {
printf("Invalid query.\n");
exit(0);
}
S += B[i];
}
if (S > W) {
printf("Invalid query.\n");
exit(0);
}
numQueries++;
if (numQueries > maxQueries) {
printf("Too many queries.\n");
exit(0);
}
int cache[2][205];
int num[2][205];
char taken[105][205];
for (i=0;i<205;++i) {
cache[1][i] = 0;
num[1][i] = 0;
}
for (i=0;i<N;++i) {
int v = B[i]+1;
int ii = i&1;
int o = ii^1;
for (j=0;j<=W;++j) {
cache[ii][j] = cache[o][j];
num[ii][j] = num[o][j];
taken[i][j] = 0;
}
for (j=W;j>=v;--j) {
int h = cache[o][j-v] + P[i];
int hn = num[o][j-v] + 1;
if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
cache[ii][j] = h;
num[ii][j] = hn;
taken[i][j] = 1;
} else {
taken[i][j] = 0;
}
}
}
int cur = W;
for (i=N-1;i>=0;--i) {
R[i] = taken[i][cur] ? (B[i] + 1) : 0;
cur -= R[i];
}
}
static void runGame(int F) {
int i;
scanf("%d %d",&N,&W);
for (i=0;i<N;++i) {
scanf("%d",&P[i]);
}
numQueries = 0;
if (F == 1) {
printf("%d\n", minValue(N, W));
} else if (F == 2) {
printf("%d\n", maxValue(N, W));
} else if (F == 3) {
printf("%d\n", greaterValue(N, W));
} else if (F == 4) {
int userP[105];
allValues(N, W, userP);
for (i=0;i<N;i++) {
printf("%d ",userP[i]);
}
printf("\n");
}
printf("Made %d calls to playRound.\n", numQueries);
}
static void grader() {
int i;
int F, G;
scanf("%d %d",&F,&G);
for (i=0;i<G;i++) {
runGame(F);
}
}