This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cave.h"
#include<bits/stdc++.h>
using namespace std;
int n;
int matched[5000];
int door[5000];
int det[5000][3];
bool fp=false;
void foundpath(int arr[]){
for(int i=0;i<n;i++){
if(matched[i]==-1){
matched[i]=arr[i];
arr[i]=(arr[i]+1)%2;
int val=tryCombination(arr);
door[i]=val;
arr[i]=(arr[i]+1)%2;
}
}
return;
}
void calc(int x){
if(fp==true)return;
int a=det[x][0],b=det[x][1],c=det[x][2];
if(b==c){
matched[b]=a;
door[b]=x;
return;
}
int arr[n];
for(int i=0;i<n;i++){
if(matched[i]!=-1)arr[i]=matched[i];
else arr[i]=(a+1)%2;
}
for(int i=b;i<=(b+c)/2;i++)if(matched[i]==-1)arr[i]=a;
int val=tryCombination(arr);
if(val==-1){
foundpath(arr);
fp=true;
return;
}
else if(val>x){
det[x][2]=(b+c)/2;
calc(x);
}
else if(val==x){
det[x][1]=(b+c)/2+1;
calc(x);
}
else {
det[val][0]=(a+1)%2;
det[val][1]=b;
det[val][2]=(b+c)/2;
calc(val);
calc(x);
}
return;
}
void exploreCave(int N) {
n=N;
for(int i=0;i<n;i++){
matched[i]=door[i]=-1;
det[i][0]=-1;
det[i][1]=0;det[i][2]=n-1;
}
int arr[n];memset(arr,0,sizeof(arr));
while(true){
for(int i=0;i<n;i++)if(matched[i]!=-1)arr[i]=matched[i];
int val=tryCombination(arr);
if(val==-1){foundpath(arr);break;}
det[val][0]=1;
calc(val);
}
int S[n];
int D[n];
for(int i=0;i<n;i++){S[i]=matched[i];D[i]=door[i];}
answer(S,D);
return;
}
/*
./compile_cpp.sh
*/
# | 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... |