이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef __CAVE_H__
#define __CAVE_H__
#ifdef __cplusplus
extern "C" {
#endif
int tryCombination(int S[]);
void answer(int S[], int D[]);
void exploreCave(int N);
#ifdef __cplusplus
}
#endif
#endif /* __CAVE_H__ */
#include <iostream>
#include <vector>
using namespace std;
int* S;
int* D;
int* Q;
int n;
//switch_state, switch_door, query
void b_search(int door, int pos, int a, int b)
{
if(a == b)
{
D[a] = door;
S[a] = pos;
}
else
{
int m = (a+b)/2;
for(int i = 0; i < n; i++)
{
if(S[i] != -1) Q[i] = S[i];
else
{
if(a <= i && i <= m) Q[i] = pos;
else Q[i] = !pos;
}
}
int q = tryCombination(Q);
if(q == door) b_search(door, pos, m+1, b);
else b_search(door, pos, a, m);
}
}
void exploreCave(int N)
{
n = N;
int s[N], d[N], q[N];
S = s;
D = d;
Q = q;
for(int i = 0; i < N; i++) S[i] = D[i] = -1;
for(int door = 0; door < N; door++)
{
for(int i = 0; i < N; i++)
{
if(S[i] == -1) Q[i] = 0;
else Q[i] = S[i];
}
int q = tryCombination(Q);
if(q == door)
{
//switch_pos of switch connected to door 1 = 1
b_search(door, 1, 0, N-1);
}
else
{
b_search(door, 0, 0, N-1);
}
}
answer(s, d);
}
# | 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... |