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>
using namespace std;
#include"library.h"
#define N 1005
bitset<N> vis;
vector<int> now,ans;
void Solve(int n){
if(n==1){
ans.push_back(1);
Answer(ans);
return ;
}
int i,sz,x,y,head,l,r,mid,cnt;
now.resize(n);
for(i=0;i<n;i++)now[i]=1;
for(i=0;i<n;i++){
now[i]=0;
x=Query(now);
now[i]=1;
if(x==1){head=i;break;}
}
for(i=0;i<n;i++)now[i]=0;
vis[head]=true;
ans.push_back(head+1);
for(sz=n-1;sz>0;sz--){
l=1,r=sz;
while(l<r){
mid=(l+r)/2;
for(i=0,cnt=0;i<n&&cnt<mid;i++)if(!vis[i])now[i]=1,cnt++;
x=Query(now);
now[head]=1;
y=Query(now);
now[head]=0;
for(i=0,cnt=0;i<n&&cnt<mid;i++)if(!vis[i])now[i]=0,cnt++;
if(x==y)r=mid;
else l=mid+1;
}
for(i=0,cnt=0;i<n&&cnt<l;i++)if(!vis[i])cnt++;
ans.push_back(i);
head=i-1;
vis[head]=true;
}
Answer(ans);
return ;
}
Compilation message (stderr)
library.cpp: In function 'void Solve(int)':
library.cpp:26:23: warning: 'head' may be used uninitialized in this function [-Wmaybe-uninitialized]
26 | ans.push_back(head+1);
| ~~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |