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<bits/stdc++.h>
#include<cave.h>
using namespace std;
int result[5000],match[5000],sent[5000];
bool iflastopen,fixed_[5000];
void change(int a, int b){
    for(int i=a;i<=b;i++){
        if(!fixed_[i])
            sent[i]=!sent[i];
    }
}
void exploreCave(int n){
    for(int j=0;j<n;j++){
        if(tryCombination(sent)>j)
            iflastopen=1;
        else
            iflastopen=0;
        int pocz=0;
        int kon=n-1;
        while(pocz!=kon){
            int sr=(pocz+kon)/2;
            change(pocz,sr);
            int ak=tryCombination(sent);
            if((ak>j)==iflastopen){
                pocz=sr+1;
            }
            else{
                kon=sr-1;
                iflastopen=!iflastopen;
            }
        }
        if(iflastopen){
            match[j]=pocz;
            fixed_[pocz]=1;
        }
        else{
            match[j]=pocz;
            fixed_[pocz]=1;
            sent[pocz]=!sent[pocz];
        }
    }
    answer(sent,match);
}
| # | 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... |