# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
951415 | svitlanatsvit | Cave (IOI13_cave) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
using namespace std;
int tryCombination(vector<int> S) {
// This function will be provided by the grader
// It allows us to try a combination of switches and returns the first closed door
// If all doors are open, it returns -1
// The grader will ensure this function runs in O(N) time
// It may be called at most 70,000 times
}
void answer(vector<int> S, vector<int> D) {
// This procedure should be called when we have identified the correct positions of switches
// and the doors each switch is connected to
// It will cause the program to exit
// The format of parameters matches that of the tryCombination function
}
void exploreCave(int N) {
vector<int> switches(N, 0); // Initialize all switches to up position initially
// Try different combinations of switches to determine the correct position for each switch
// Use binary search strategy
int left = 0, right = N;
while (left < right) {
int mid = (left + right) / 2;
switches[mid] = 1; // Set the switch at mid position to down
int first_closed_door = tryCombination(switches);
if (first_closed_door == -1) {
// All doors are open, adjust the search range
right = mid;
} else {
// Adjust the search range based on the position of the first closed door
left = first_closed_door;
}
switches[mid] = 0; // Reset the switch position for next iteration
}
// Once we have determined the correct positions of switches, assign the doors each switch is connected to
vector<int> doors(N);
for (int i = 0; i < N; ++i) {
doors[i] = left + i;
}
// Provide the solution to the grader
answer(switches, doors);
}
// Example usage
int main() {
int N = 4; // Number of switches and doors
exploreCave(N);
return 0;
}