이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXS = 5001;
int sw[MAXS], opens[MAXS], definedcomb[MAXS];
void funfun(int l, int r, int color, int currdoor)
{
// base case:
if (l==r){
definedcomb[r]=color;
opens[r]=currdoor;
return;
}
// general case:
int mid=(l+r)/2;
for (int i=l; i<=mid; i++)
if (definedcomb[i]==-1)
sw[i]=color;
int complement=color ^ 1;
for (int i=mid+1; i<=r; i++)
if (definedcomb[i]==-1)
sw[i]=complement;
int temp=tryCombination(sw);
if (temp!=currdoor){
funfun(l, mid, color, currdoor);
}else{
for(int i=l; i<=mid; i++)
if (definedcomb[i]==-1)
sw[i]=complement;
for (int i=mid+1; i<=r; i++)
if (definedcomb[i]==-1)
sw[i]=color;
funfun(mid+1, r, color, currdoor);
}
}
void exploreCave(int N)
{
memset(opens, -1, sizeof opens);
memset(definedcomb, -1, sizeof definedcomb);
int n=N;
for (int i=0; i<n; i++){ //find out the switch of the ith door
memset(sw, 0, sizeof sw);
for (int j=0; j<n; j++)
if (definedcomb[j]!=-1)
sw[j]=definedcomb[j];
int temp=tryCombination(sw);
if (temp!=i){
//ok this opens the door
funfun(0, n-1, 0, i);
}else{
for (int j=0; j<n; j++){
if (definedcomb[j]==-1) sw[j]=1;
else sw[j]=definedcomb[j];
}
funfun(0, n-1, 1, i);
}
}
answer(definedcomb, opens);
}
# | 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... |