Submission #784128

#TimeUsernameProblemLanguageResultExecution timeMemory
784128BoasCave (IOI13_cave)C++17
0 / 100
339 ms608 KiB
#include <bits/stdc++.h> #include "cave.h" using namespace std; #define ALL(x) (x).begin(), (x).end() #define set(x, v) fill(ALL(x), v) typedef vector<int> vi; // map<vi, int> tryCombi; constexpr bool debug = false; int ownTryCombination(vi &switches) { if (debug) { cerr << endl << "TryCombination: "; for (int t : switches) { cerr << t << " "; } cerr << endl; } int res; // if (tryCombi.find(switches) != tryCombi.end()) //{ // res = tryCombi[switches]; //} // else { res = tryCombination(switches.data()); // tryCombi[switches] = res; } if (debug) cerr << "Result: " << res << endl; return res; } void exploreCave(int N) { vi switches(N, 0); vi revS(N, 0); // the correct position of each switch corresponding to door i // vi S(N, 0); // the correct position of each switch vi D(N, -1); // element D[i] should contain the door number that switch i is connected to vi revD(N, -1); // element revD[i] should contain the switch number that door i is connected to bool done = false; for (int i = 0; i < N; i++) { if (i > 0) set(switches, 0); for (int j = 0; j < N; j++) { if (revD[j] == -1) break; switches[revD[j]] = revS[j]; } revS[i] = ownTryCombination(switches) == i; int min = 0, max = N - 1; while (max - min > 0) { int s = (max + min) / 2; set(switches, !revS[i]); fill(switches.begin() + min, switches.begin() + s + 1, revS[i]); for (int j = 0; j < N; j++) { if (revD[j] == -1) break; switches[revD[j]] = revS[j]; } int d = ownTryCombination(switches); if (d == -1) { done = true; break; } if (d > i) { max = s; } else { min = s + 1; } } if (done) break; cerr << "inx is " << min << endl; revD[i] = min; D[min] = i; } for (int i = 0; i < N; i++) { if (D[i] != -1) continue; switches[i] = !switches[i]; int d = ownTryCombination(switches); D[i] = d; switches[i] = !switches[i]; } answer(switches.data(), D.data()); }
#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...