Submission #230865

#TimeUsernameProblemLanguageResultExecution timeMemory
230865AASGCave (IOI13_cave)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define MAX_N 5000 #define MAX_CALLS 70000 #define fail(s, x...) do { \ fprintf(stderr, s "\n", ## x); \ exit(1); \ } while(0) #define N koala #define realS kangaroo #define realD possum #define inv platypus #define num_calls echidna static int N; static int realS[MAX_N]; static int realD[MAX_N]; static int inv[MAX_N]; static int num_calls; void answer(int S[], int D[]) { int i; int correct = 1; for (i = 0; i < N; ++i) if (S[i] != realS[i] || D[i] != realD[i]) { correct = 0; break; } if (correct) printf("CORRECT\n"); else printf("INCORRECT\n"); for (i = 0; i < N; ++i) { if (i > 0) printf(" "); printf("%d", S[i]); } printf("\n"); for (i = 0; i < N; ++i) { if (i > 0) printf(" "); printf("%d", D[i]); } printf("\n"); exit(0); } int tryCombination(int S[]) { int i; if (num_calls >= MAX_CALLS) { printf("INCORRECT\nToo many calls to tryCombination().\n"); exit(0); } ++num_calls; for (i = 0; i < N; ++i) if (S[inv[i]] != realS[inv[i]]) return i; return -1; } using namespace std; void exploreCave(int N) { int n=N; int R[n];int P[n]; int aux1[n],aux2[n]; memset(aux1,1,sizeof(aux1)); memset(P,0,sizeof(P)); for(int i=0;i<n;i++){ R[i]=1; P[i]=0; } for(int i=0;i<n;i++){ for(int i=0;i<n;i++)aux2[i]=R[i]; int p1=0,p2=n; int x=tryCombination(aux2); while(abs(p1-p2)!=1){ int p3=(p1+p2)/2; for(int i=0;i<n;i++){ if(P[i]==0){ aux2[i]=0; } } int y=tryCombination(aux2); if(x>i && y>i){ p1=p3; }else{ p2=p3-1; } } if(aux2[p2]==1){aux2[p2]=0;} else aux2[p2]=1; if(tryCombination(aux2)<n+1){ if(aux2[p2]==1){aux2[p2]=0;} else aux2[p2]=1; R[p2]=aux2[p2]; P[p2]=n+1; } } answer(R,P); } int init() { int i, res; FILE *f = fopen("cave.in", "r"); if (!f) fail("Failed to open input file."); res = fscanf(f, "%d", &N); for (i = 0; i < N; ++i) { res = fscanf(f, "%d", &realS[i]); } for (i = 0; i < N; ++i) { res = fscanf(f, "%d", &realD[i]); inv[realD[i]] = i; } num_calls = 0; return N; } int main() { int N; N = init(); exploreCave(N); printf("INCORRECT\nYour solution did not call answer().\n"); return 0; }

Compilation message (stderr)

cave.cpp: In function 'int init()':
cave.cpp:112:12: warning: variable 'res' set but not used [-Wunused-but-set-variable]
     int i, res;
            ^~~
/tmp/ccRgK4UY.o: In function `init()':
cave.cpp:(.text+0x3c0): multiple definition of `init()'
/tmp/ccdSBYpM.o:grader.c:(.text+0x140): first defined here
/tmp/ccRgK4UY.o: In function `main':
cave.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccdSBYpM.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccdSBYpM.o: In function `main':
grader.c:(.text.startup+0xc): undefined reference to `exploreCave'
collect2: error: ld returned 1 exit status