Submission #1104191

#TimeUsernameProblemLanguageResultExecution timeMemory
1104191IanisCave (IOI13_cave)C++17
100 / 100
237 ms840 KiB
#pragma GCC optimize("Ofast,unroll-loops") #include "cave.h" #include <iostream> using namespace std; #ifdef LOCAL #include <stdio.h> #include <stdlib.h> #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; } 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; } #endif const int NMAX = 5005; int n; int a[NMAX]; int ans[NMAX]; int pos[NMAX]; int swi[NMAX]; int query(int s[]) { int q = tryCombination(s); return q == -1 ? n : q; } void make_seq(bool val, short l, short r, int cnt) { fill(a, a + n, !val); fill(a + l, a + r + 1, val); for (int i = 0; i < cnt; i++) { a[swi[i]] = ans[swi[i]]; } } int find_switch(int door) { int l = 0, r = n - 1; bool val = 1; make_seq(1, 0, n - 1, door); if (query(a) <= door) { val = 0; } while (l <= r) { int mid = (l + r) >> 1; make_seq(val, l, mid, door); if (query(a) <= door) { l = mid + 1; } else { r = mid - 1; } } swi[door] = r + 1; ans[r + 1] = val; return r + 1; } void exploreCave(int N) { n = N; for (int i = 0; i < n; i++) { int x = find_switch(i); pos[x] = i; } make_seq(0, n, n, n); answer(a, pos); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...