제출 #1274188

#제출 시각아이디문제언어결과실행 시간메모리
1274188RomanLeshchukCave (IOI13_cave)C++20
0 / 100
284 ms524 KiB
#include "cave.h" #include <vector> #include <iostream> using namespace std; static int N; static vector<int> doorOfSwitch; // to what door is switch linked, -1 if not determined static vector<int> switchOfDoor; // to what switch is door linked, -1 if not determined static vector<int> mustBeDown; // i-th switch must be down to open corresponding door, false if not determined void exploreCave(int n) { N = n; doorOfSwitch = vector<int>(N, -1); switchOfDoor = vector<int>(N, -1); mustBeDown = vector<int>(N, 0); // iterating over doors, determining corresponding switches one by one for (int i = 0; i < N; ++i) { // making all unknown up for (int j = 0; j < N; ++j) { if (doorOfSwitch[j] == -1) { mustBeDown[j] = 0; } } // determining is corresponding door switch must be down // switches linked to prev doors are correct, other are up // if must be down, then it will stuck exactly on i-th door //cout << "Ask: "; for (int i = 0; i < N; ++i) { //cout << mustBeDown[i] << ' '; } //cout << '\n'; int switchMustBeDown = tryCombination(mustBeDown.data()) == i + 1; //cout << "Got: " << tryCombination(mustBeDown.data()) << '\n'; //cout << "Switch of door " << i << " must be " << switchMustBeDown << '\n'; // now determining which exactly switch is linked with i-th door int l = 0; int r = N - 1; int switchPos = N - 1; while (l <= r) { int mid = (l + r) / 2; for (int j = 0; j <= mid; ++j) // here filling switches with current good, and only linked to next doors { if (doorOfSwitch[j] == -1) { mustBeDown[j] = switchMustBeDown; } } for (int j = mid + 1; j < N; ++j) // here filling switches with current bad, and only linked to next doors { if (doorOfSwitch[j] == -1) { mustBeDown[j] = !switchMustBeDown; } } //cout << "Ask: "; for (int i = 0; i < N; ++i) { //cout << mustBeDown[i] << ' '; } //cout << '\n'; //cout << "Got: "; int queryRes = tryCombination(mustBeDown.data()); //cout << queryRes << '\n'; if (queryRes == i + 1) { // stuck, must search further l = mid + 1; } else { // good, must narrow search r = mid - 1; switchPos = mid; } } //cout << switchPos << '\n'; mustBeDown[switchPos] = switchMustBeDown; doorOfSwitch[switchPos] = i; switchOfDoor[i] = switchPos; } for (int i = 0; i < N; ++i) { ++doorOfSwitch[i]; } answer(mustBeDown.data(), doorOfSwitch.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...