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"
bool keep[5005];
int s[5005],d[5005];
void flip(int l,int r) {
for (int j=l;j<=r;j++) {
if (!keep[j]) s[j]=1-s[j];
}
}
void exploreCave(int N) {
for (int i=1;i<=N;i++) s[i]=0;
int x;
int l,r,mid;
for (int i=1;i<=N;i++) {
x=tryCombination(s);
if (x!=i) flip(1,N);
l=1,r=N;
while (l<=r) {
mid=(l+r)>>1;
flip(l,mid);
x=tryCombination(s);
if (l==r) {
if (x==i) s[l]=1-s[l],keep[l]=1;
else keep[l]=1;
d[l]=i;
break;
}
if (x!=i) {
flip(l,mid);
r=mid;
} else {
l=mid+1;
}
}
}
answer(s,d);
}
# | 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... |