Submission #120950

#TimeUsernameProblemLanguageResultExecution timeMemory
120950RahulKoala Game (APIO17_koala)C++17
Compilation error
0 ms0 KiB
#include "koala.h" using namespace std; #define SZ(v) int((v).size()) #define ALL(vec) (vec).begin(),(vec).end() int B[500], R[500]; 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); } } int minValue(int n, int w) { for (int i = 0; i < 100; ++i) { B[i] = i < 51; } playRound(B, R); int m = -1; for (int i = 0; i < 51; ++i) { if (R[i] == 0) { m = i; } // else assert (R[i] == 2); } for (int i = 0; i < 100; ++i) { B[i] = i >= 50; } B[m] = 1; if (m == 50) B[49] = 1; playRound(B, R); int res = -1; for (int i = 50; i < 100; ++i) { if (R[i] == 0) { res = i; } // else assert (R[i] == 2); } if (res != -1) return res; if (m == 50) return 49; else return m; } int maxValue(int n, int w) { return 0; } int greaterValue(int n, int w) { return 0; } int allValues(int n, int w, int *P) { return 0; }

Compilation message (stderr)

koala.cpp: In function 'void playRound(int*, int*)':
koala.cpp:11:16: error: 'N' was not declared in this scope
     for (i=0;i<N;++i) {
                ^
koala.cpp:12:37: error: 'W' was not declared in this scope
         if ( !(B[i] >= 0 && B[i] <= W) ) {
                                     ^
koala.cpp:13:13: error: 'printf' was not declared in this scope
             printf("Invalid query.\n");
             ^~~~~~
koala.cpp:13:13: note: suggested alternative: 'int'
             printf("Invalid query.\n");
             ^~~~~~
             int
koala.cpp:14:13: error: 'exit' was not declared in this scope
             exit(0);
             ^~~~
koala.cpp:18:13: error: 'W' was not declared in this scope
     if (S > W) {
             ^
koala.cpp:19:9: error: 'printf' was not declared in this scope
         printf("Invalid query.\n");
         ^~~~~~
koala.cpp:19:9: note: suggested alternative: 'int'
         printf("Invalid query.\n");
         ^~~~~~
         int
koala.cpp:20:9: error: 'exit' was not declared in this scope
         exit(0);
         ^~~~
koala.cpp:23:5: error: 'numQueries' was not declared in this scope
     numQueries++;
     ^~~~~~~~~~
koala.cpp:24:22: error: 'maxQueries' was not declared in this scope
     if (numQueries > maxQueries) {
                      ^~~~~~~~~~
koala.cpp:25:9: error: 'printf' was not declared in this scope
         printf("Too many queries.\n");
         ^~~~~~
koala.cpp:25:9: note: suggested alternative: 'int'
         printf("Too many queries.\n");
         ^~~~~~
         int
koala.cpp:26:9: error: 'exit' was not declared in this scope
         exit(0);
         ^~~~
koala.cpp:38:16: error: 'N' was not declared in this scope
     for (i=0;i<N;++i) {
                ^
koala.cpp:42:21: error: 'W' was not declared in this scope
         for (j=0;j<=W;++j) {
                     ^
koala.cpp:47:16: error: 'W' was not declared in this scope
         for (j=W;j>=v;--j) {
                ^
koala.cpp:48:37: error: 'P' was not declared in this scope
             int h = cache[o][j-v] + P[i];
                                     ^
koala.cpp:60:15: error: 'W' was not declared in this scope
     int cur = W;
               ^
koala.cpp:61:12: error: 'N' was not declared in this scope
     for (i=N-1;i>=0;--i) {
            ^
koala.cpp: In function 'void runGame(int)':
koala.cpp:70:20: error: 'N' was not declared in this scope
     scanf("%d %d",&N,&W);
                    ^
koala.cpp:70:23: error: 'W' was not declared in this scope
     scanf("%d %d",&N,&W);
                       ^
koala.cpp:70:5: error: 'scanf' was not declared in this scope
     scanf("%d %d",&N,&W);
     ^~~~~
koala.cpp:72:21: error: 'P' was not declared in this scope
         scanf("%d",&P[i]);
                     ^
koala.cpp:75:5: error: 'numQueries' was not declared in this scope
     numQueries = 0;
     ^~~~~~~~~~
koala.cpp:77:9: error: 'printf' was not declared in this scope
         printf("%d\n", minValue(N, W));
         ^~~~~~
koala.cpp:77:9: note: suggested alternative: 'int'
         printf("%d\n", minValue(N, W));
         ^~~~~~
         int
koala.cpp:79:9: error: 'printf' was not declared in this scope
         printf("%d\n", maxValue(N, W));
         ^~~~~~
koala.cpp:79:9: note: suggested alternative: 'int'
         printf("%d\n", maxValue(N, W));
         ^~~~~~
         int
koala.cpp:81:9: error: 'printf' was not declared in this scope
         printf("%d\n", greaterValue(N, W));
         ^~~~~~
koala.cpp:81:9: note: suggested alternative: 'int'
         printf("%d\n", greaterValue(N, W));
         ^~~~~~
         int
koala.cpp:86:13: error: 'printf' was not declared in this scope
             printf("%d ",userP[i]);
             ^~~~~~
koala.cpp:86:13: note: suggested alternative: 'int'
             printf("%d ",userP[i]);
             ^~~~~~
             int
koala.cpp:88:9: error: 'printf' was not declared in this scope
         printf("\n");
         ^~~~~~
koala.cpp:88:9: note: suggested alternative: 'int'
         printf("\n");
         ^~~~~~
         int
koala.cpp:90:5: error: 'printf' was not declared in this scope
     printf("Made %d calls to playRound.\n", numQueries);
     ^~~~~~
koala.cpp:90:5: note: suggested alternative: 'int'
     printf("Made %d calls to playRound.\n", numQueries);
     ^~~~~~
     int
koala.cpp: In function 'void grader()':
koala.cpp:97:5: error: 'scanf' was not declared in this scope
     scanf("%d %d",&F,&G);
     ^~~~~
koala.cpp: In function 'int allValues(int, int, int*)':
koala.cpp:137:5: error: ambiguating new declaration of 'int allValues(int, int, int*)'
 int allValues(int n, int w, int *P) {
     ^~~~~~~~~
In file included from koala.cpp:1:0:
koala.h:9:6: note: old declaration 'void allValues(int, int, int*)'
 void allValues(int N, int W, int *P);
      ^~~~~~~~~
koala.cpp: At global scope:
koala.cpp:93:13: warning: 'void grader()' defined but not used [-Wunused-function]
 static void grader() {
             ^~~~~~