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"
#include<bits/stdc++.h>
using namespace std;
/*
int tryCombination(int S[]);
void answer(int S[], int D[]);
void exploreCave(int N);
*/
// int n;
// int S[]={1,1,1,0};
// int D[]={3,1,0,2};
// int F[]={2,1,3,0};
// int tryCombination(int s[]){
// int ac=0;
// for(int i=0; i<n; i++){
// if(s[F[i]]==S[F[i]])ac++;
// else break;
// }
// return ac;
// }
// void answer(int s[], int d[]){
// // cout<<"try: \n";
// // for(int i=0; i<n; i++)cout<<s[i]<<' ';cout<<'\n';
// // for(int i=0; i<n; i++)cout<<S[i]<<' ';cout<<'\n';
// // cout<<endl;
// // cout<<"try: \n";
// // for(int i=0; i<n; i++)cout<<d[i]<<' ';cout<<'\n';
// // for(int i=0; i<n; i++)cout<<D[i]<<' ';cout<<'\n';
// if(tryCombination(s)==n)cout<<"YES";
// else cout<<"NO";
// }
void exploreCave(int N) {
int d[N]={},s[N]={};
bool dn[N]={};
int ts=tryCombination(s),ts2;
for(int i=0; i<N; i++){
int l=0,r=N-1;
while(l<=r){
if(l==r){
// cout<<"FOUND "<<i<<" in "<<l<<endl;
dn[l]=1;
d[l]=i;
// s[l]^=1;
if(ts2<=i)s[l]^=1;
ts=tryCombination(s);
break;
}
int md=(l+r)/2;
for(int j=l; j<=md; j++){
if(dn[j])continue;
s[j]^=1;
}
ts2=tryCombination(s);
// cout<<ts<<" # "<<l<<' '<<md<<' '<<r<<" !! ";for(int i=0; i<N; cout<<s[i++]<<' ');cout<<"!! "<<ts2<<endl;
// for(int j=l; j<=md; j++){
// if(dn[j])continue;
// s[j]^=1;
// }
if((ts<=i && ts2>=i+1) || (ts>=i+1 && ts2<=i)){
r=md;
ts=ts2;
}
else{
l=md+1;
}
}
}
answer(s,d);
}
// signed main(){
// n=4;
// exploreCave(n);
// }
Compilation message (stderr)
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:49:17: warning: 'ts2' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | if(ts2<=i)s[l]^=1;
| ^~
# | 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... |