# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
653902 | AbdelmagedNour | Cave (IOI13_cave) | C++17 | 0 ms | 0 KiB |
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>
#pragma GCC optimize("Ofast")
using namespace std;
const int N=5005;
int s[N],d[N],done[N],now;
bool check(int md){
for(int i=0;i<=md;i++)s[i]^=(!done[i]);
int x=tryCombination(s);
for(int i=0;i<=md;i++)s[i]^=(!done[i]);
return x>now||x==-1;
}
void exploreCave(int n){
for(int i=0;i<n;i++){
now=i;
int x=tryCombination(s);
for(int j=0;j<n&&(x>i||x==-1);j++)s[j]^=(!done[j]);
int l=0,r=n-1,ans;
while(l<=r){
int md=(l+r)>>1;
if(check(md))r=(ans=md)-1;
else l=md+1;
}
d[ans]=i;
done[ans]=1;
s[ans]^=1;
}
answer(s,d);
}