Submission #711950

#TimeUsernameProblemLanguageResultExecution timeMemory
711950thimote75Cave (IOI13_cave)C++14
100 / 100
1049 ms716 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; #define MAX_N 5000 int currentDoor = 0; static int S[MAX_N]; static int F[MAX_N]; static int D[MAX_N]; int nbSwitch; void makeCombination (int left, int right, int t0, int t1) { int c = 0; for (int i = 0; i < nbSwitch; i ++) { if (F[i] != -1) { S[i] = F[i]; } else { S[i] = left <= c && c <= right ? t1 : t0; c ++; } } } int nbTry = 0; int tryComb (int left, int right, int t0, int t1) { makeCombination(left, right, t0, t1); int v = tryCombination(S); nbTry ++; if (v == -1) return nbSwitch + 1; return v; } int getValid (int door) { return tryComb(0, nbSwitch - 1 - door, 0, 1) > door ? 1 : 0; } int getDoor (int door, int target) { int n_target = 1 - target; int a = 0; int b = nbSwitch - 1 - door; while (a + 1 < b) { int c = (a + b) >> 1; if (tryComb(a, c, n_target, target) > door) { b = c; } else { a = c; } } int na = 0; int nb = 0; for (int i = a; i >= 0; na ++) i -= F[na] == -1 ? 1 : 0; for (int i = b; i >= 0; nb ++) i -= F[nb] == -1 ? 1 : 0; na --; nb --; return tryComb(a, a, n_target, target) > door ? na : nb; } #define di pair<int, int> di getDoor (int door) { int target = getValid(door); return { getDoor(door, target), target }; } void solve (int door) { di data = getDoor(door); int idSwitch = data.first; F[idSwitch] = data.second; D[idSwitch] = door; } void exploreCave(int N) { nbSwitch = N; for (int i = 0; i < N; i ++) F[i] = -1; // Signifies that it is not fixed for (int i = 0; i < N; i ++) solve(i); answer(F, D); }
#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...