# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99269 | long10024070 | Cave (IOI13_cave) | C++11 | 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 "cave.h"
void Fill(int l, int r, bool d)
{
for (int i=l;i<=r;++i)
if (Val[i] != -1)
s[i] = True[i];
else
s[i] = d;
}
void exploreCave(int n)
{
fill(Val,Val+n,-1);
for (int i=0;i<n;++i) {
Fill(0,n-1,0);
bool fl = (i == tryCombination(s));
// cout << " ";
// for (int i=0;i<n;++i)
// cout << s[i] << ' ';
// cout << '\n';
// cout << i << ' ' << fl << ' ' << tryCombination(s) << '\n';
int l = 0;
int r = n - 1;
while (l <= r) {
int m = (l + r) / 2;
Fill(1,n-1,fl^1);
Fill(l,m,fl);
Fill(m+1,r,fl^1);
// cout << " ";
// for (int i=0;i<n;++i)
// cout << s[i] << ' ';
// cout << '\n';
// cout << i << ' ' << l << ' ' << r << ' ' << m << ' ' << tryCombination(s) << '\n';
if (tryCombination(s) == i)
l = m + 1;
else
r = m - 1;
}
// cout << l << ' ' << fl << '\n';
True[l] = fl;
Val[l] = i;
}
answer(True,Val);
}