이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include "cave.h"
using namespace std;
int status[5005];
int door[5005];
int locked[5005];
///Binary Search
///Update ranges
///Greedy
void reset(int n, int L, int R, int correct) ///Set segment of array to correct
{
for (int i = L; i <= R; i++) {
if (locked[i]) continue;
status[i] = correct;
}
}
int binarySearch(int n, int i, int correct) ///Perform binary search on i-th door
{
int L = 0, R = n - 1;
while (L < R) {
int mid = (L + R) / 2;
reset(n, L, mid, correct);
reset(n, mid + 1, R, !correct);
if (tryCombination(status) != i)
R = mid;
else
L = mid + 1;
}
return L;
}
void exploreCave(int N) {
for (int i = 0; i < N; i++) {
reset(N, 0, N, 0);
int ans = tryCombination(status); //Obtain correct state for door
int correct = (ans == i);
int sw = binarySearch(N, i, correct);
status[sw] = correct;
door[sw] = i;
locked[sw] = 1; //Mantain that door open in order to see beyond
}
answer(status, door);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |