답안 #249281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249281 2020-07-14T15:14:56 Z SamAnd 코알라 (APIO17_koala) C++17
컴파일 오류
0 ms 0 KB
#include "koala.h"

#include <stdio.h>
#include <stdlib.h>

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("input.txt", "r", stdin);
    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);
    }
}

Compilation message

koala.cpp: In function 'int main()':
koala.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("input.txt", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp: In function 'void grader()':
koala.cpp:111:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&F,&G);
     ~~~~~^~~~~~~~~~~~~~~
koala.cpp: In function 'void runGame(int)':
koala.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&W);
     ~~~~~^~~~~~~~~~~~~~~
koala.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&P[i]);
         ~~~~~^~~~~~~~~~~~
/tmp/ccPCfsaf.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccA1Qq5m.o:koala.cpp:(.text.startup+0x0): first defined here
/tmp/ccPCfsaf.o: In function `playRound(int*, int*)':
grader.cpp:(.text+0x260): multiple definition of `playRound(int*, int*)'
/tmp/ccA1Qq5m.o:koala.cpp:(.text+0x1a0): first defined here
/tmp/ccA1Qq5m.o: In function `runGame(int)':
koala.cpp:(.text+0xe2): undefined reference to `allValues(int, int, int*)'
koala.cpp:(.text+0x147): undefined reference to `minValue(int, int)'
koala.cpp:(.text+0x177): undefined reference to `maxValue(int, int)'
koala.cpp:(.text+0x187): undefined reference to `greaterValue(int, int)'
/tmp/ccPCfsaf.o: In function `runGame(int)':
grader.cpp:(.text+0x137): undefined reference to `minValue(int, int)'
grader.cpp:(.text+0x16b): undefined reference to `allValues(int, int, int*)'
grader.cpp:(.text+0x1bf): undefined reference to `maxValue(int, int)'
grader.cpp:(.text+0x1ef): undefined reference to `greaterValue(int, int)'
collect2: error: ld returned 1 exit status