# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670718 | sofija6 | 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.
#include <bits/stdc++.h>
#define ll long long
#include "cave.h"
using namespace std;
void exploreCave(int N)
{
ll a[N],S[N],D[N];
bool f[N];
for (ll i=0;i<N;i++)
{
a[i]=1;
f[i]=false;
}
for (ll i=0;i<N;i++)
{
if (tryCombination(a)!=i)
{
for (ll j=0;j<N;j++)
{
if (!f[j])
a[j]=1-a[j];
}
}
ll l=0,r=N-i,mid,cnt,ans,last;
while (l<=r)
{
mid=(l+r)/2;
cnt=mid;
for (ll j=0;j<N;j++)
{
if (!cnt)
break;
if (!f[j])
{
a[j]=1-a[j];
cnt--;
last=j;
}
}
if (tryCombination(a)==i)
l=mid+1;
else
{
r=mid-1;
ans=last;
}
cnt=mid;
for (ll j=0;j<N;j++)
{
if (!cnt)
break;
if (!f[j])
{
a[j]=1-a[j];
cnt--;
}
}
}
S[ans]=1-a[ans];
a[ans]=1-a[ans];
f[ans]=true;
D[i]=ans;
}
answer(S,D);
}
int main()
{
ll N;
cin >> N;
exploreCave(N);
return 0;
}