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>
#include "cave.h"
using namespace std;
#define MAXN 5010
int pozicija[MAXN];
int vrata[MAXN];
bool pronadjeno[MAXN];
vector<long long> nepronadjeni;
void exploreCave(int N)
{
for (long long i=0;i<N;i++) pozicija[i]=0;
for (long long i=0;i<N;i++) pronadjeno[i]=false;
for (long long i=0;i<N;i++) vrata[i]=-1;
for (long long i=0;i<N;i++)
{
for (long long j=0;j<N;j++)
{
if (pronadjeno[j]) continue;
else nepronadjeni.push_back(j);
}
long long ans0=tryCombination(pozicija);
if (ans0<=i and ans0!=-1)
{
long long l=0,r=nepronadjeni.size()-1;
long long rez=-1;
while (l<=r)
{
long long mid=(l+r)/2;
for (long long j=0;j<=mid;j++) pozicija[nepronadjeni[j]]=1-pozicija[nepronadjeni[j]];
long long ans=tryCombination(pozicija);
if (ans>i or ans==-1) {rez=mid;r=mid-1;}
else l=mid+1;
for (long long j=0;j<=mid;j++) pozicija[nepronadjeni[j]]=1-pozicija[nepronadjeni[j]];
}
pozicija[nepronadjeni[rez]]=1;
vrata[nepronadjeni[rez]]=i;
pronadjeno[nepronadjeni[rez]]=true;
}
else
{
long long l=0,r=nepronadjeni.size()-1;
long long rez=-1;
while (l<=r)
{
long long mid=(l+r)/2;
for (long long j=0;j<=mid;j++) pozicija[nepronadjeni[j]]=1-pozicija[nepronadjeni[j]];
long long ans=tryCombination(pozicija);
if (ans==i) {rez=mid;r=mid-1;}
else l=mid+1;
for (long long j=0;j<=mid;j++) pozicija[nepronadjeni[j]]=1-pozicija[nepronadjeni[j]];
}
vrata[nepronadjeni[rez]]=i;
pronadjeno[nepronadjeni[rez]]=true;
}
nepronadjeni.clear();
}
answer(pozicija,vrata);
}
# | 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... |