Submission #523306

#TimeUsernameProblemLanguageResultExecution timeMemory
523306lucriCave (IOI13_cave)C++17
Compilation error
0 ms0 KiB
#include <stdio.h> #include <stdlib.h> #include <algorithm> //#include "cave.h" #define MAX_N 5000 #define MAX_CALLS 70000 #define fail(s, x...) do { \ fprintf(stderr, s "\n", ## x); \ exit(1); \ } while(0) /* Symbol obfuscation */ #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; } void exploreCave(int N) { int poz[N+5]={0},link[N+5]; std::pair <int,int>c[N+5]; bool sta[N+5]={false}; int vede=tryCombination(poz); for(int qwerty=0;qwerty<N;++qwerty) { int b=0,e=N-1; while(b<=e) { int mij=(b+e)/2; for(int i=b;i<=mij;++i) { if(sta[i]==false) poz[i]=1; } int vedeacum=tryCombination(poz); for(int i=b;i<=mij;++i) { if(sta[i]==false) poz[i]=0; } if(vedeacum==qwerty&&vede!=qwerty||vedeacum!=qwerty&&vede==qwerty) e=mij-1; else b=mij+1; } c[qwerty].first=b; c[qwerty].second=qwerty; sta[b]=true; if(vede==qwerty) { poz[b]=1; vede=tryCombination(poz); } } sort(c,c+N); for(int i=0;i<N;++i) link[i]=c[i].second; answer(poz,link); } 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 'void exploreCave(int)':
cave.cpp:96:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   96 |             if(vedeacum==qwerty&&vede!=qwerty||vedeacum!=qwerty&&vede==qwerty)
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
cave.cpp: In function 'int init()':
cave.cpp:118:12: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  118 |     int i, res;
      |            ^~~
/usr/bin/ld: /tmp/ccc4JC1R.o: in function `init()':
cave.cpp:(.text+0xc50): multiple definition of `init()'; /tmp/ccF4yNWR.o:grader.c:(.text+0x110): first defined here
/usr/bin/ld: /tmp/ccc4JC1R.o: in function `main':
cave.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccF4yNWR.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccF4yNWR.o: in function `main':
grader.c:(.text.startup+0x10): undefined reference to `exploreCave'
collect2: error: ld returned 1 exit status