# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338714 | NicolaAbusaad2014 | Cave (IOI13_cave) | C++14 | 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.
/**
* Prof.Nicola
**/
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
template<class T>void re(T&x){cin>>x;}
template<class T1,class T2> void re(pair<T1,T2>&x){re(x.first);re(x.second);}
template<class T>void re(vector<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T>void re(deque<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T1,class T2> pair<T1,T2> mp(T1&x,T2&z){return make_pair(x,z);}
long long n,turn[5001]={};
set<long>s;
set<long>::iterator t;
void con(long l,long r,long&arr[])
{
t=s.begin();
for(long i=0;i<s.size();i++){
arr[*t]=turn[*t];
t++;
}
for(long i=0;i<n&&r>=0;i++){
if(!s.count(i)){
if(l){
l--;
continue;
}
arr[i]=(arr[i]^1);
r--;
}
}
}
long long bin(long long l,long long r,long long x,long&arr[])
{
long long mid;
while(l<r){
mid=(l+r)/2;
con(l,mid,arr);
if(tryCombination(arr)==x){
l=mid+1;
}
else{
con(l,mid,arr);
r=mid;
}
}
return l;
}
void exploreCave(int N) {
n=N;
long sw[n]={},arr[n]={},ans[n]={};
long x;
for(long i=0;i<N;i++){
if(tryCombination(arr)!=i){
con(0,N-i,arr);
}
x=bin(0,N-i,i,arr);
ans[x]=i;
sw[i]=(arr[i]^1);
turn[i]=sw[i];
s.insert(x);
}
answer(sw,ans);
}