이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cave.h"
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
using namespace std;
using vi = vector<int>;
const int MAXN = 5'000;
int switches[MAXN];
// door triggered by switchID
int door[MAXN];
int gN;
// returns N instead of -1 when all doors are open
int getLastDoor()
{
int lastDoor = tryCombination(switches);
if (lastDoor == -1)
lastDoor = gN;
return lastDoor;
}
void flipSwitches(int i, int j, vi &ids)
{
for (int k = i; k <= j; k++)
switches[ids[k]] = !switches[ids[k]];
}
void exploreCave(int N)
{
gN = N;
vi unassignedSwitches;
for (int i = 0; i < N; i++)
unassignedSwitches.push_back(i);
// doors up to curDoor EXCEPT curDoor are open
for (int curDoor = 0; curDoor < N; curDoor++)
{
int doorOpen = getLastDoor() > curDoor;
int respSwitch;
int lo = 0, hi = unassignedSwitches.size() - 1;
while (lo < hi)
{
int mid = (lo + hi) / 2;
flipSwitches(lo, mid, unassignedSwitches);
int lastDoor = getLastDoor();
bool check = false;
if (doorOpen)
{
if (lastDoor == curDoor)
check = true;
}
else if (lastDoor > curDoor)
check = true;
if (check)
hi = mid;
else
lo = mid + 1;
flipSwitches(lo, mid, unassignedSwitches);
}
respSwitch = unassignedSwitches[lo];
unassignedSwitches.erase(find(all(unassignedSwitches), respSwitch));
door[respSwitch] = curDoor;
if (!doorOpen)
switches[respSwitch] = !switches[respSwitch];
}
answer(switches, 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... |