# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969855 | elotelo966 | Cave (IOI13_cave) | C++17 | 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 <bits/stdc++.h>
#include "cave.h"
using namespace std;
#define lim 5005
int n,arr[lim],arr_use[lim];
bool kesin[lim];
int tut;
vector<int> deg;
inline void change(int l,int r,int val){
int cur=0;
deg.clear();
for(int i=0;i<n;i++){
if(kesin[i])continue;
if(cur>=l && cur<=r){
arr_use[i]=val;
tut=i;
deg.push_back(i);
}
cur++;
}
}
inline int go(int deg){
int cur=0;
for(int i=0;i<n;i++){
if(kesin[i])continue;
if(deg==cur)return i;
cur++;
}
}
inline void rechange(){
for(auto ind:deg){
arr_use[ind]=0;
}
}
inline int tryCombination(int ar[]){
for(int i=0;i<n;i++)cout<<ar[i]<<" ";
cout<<'\n';
int x;cin>>x;
return x;
}
inline void change(int l,int kac,int val){
int cur=l;
kac-=l;
kac++;
while(kac){
if(kesin[cur]){
cur++;
}
else{
kac--;
arr_use[cur]=val;
}
}
}
void exploreCave(int N) {
n=N;
int ans[n],ans2[n];
for(int i=0;i<n;i++){
int door=tryCombination(arr);
if(door!=i)ans[i]=0; //cevap 0da
else ans[i]=1; // cevap 1de
int l=0,r=n-i-1;
while(l<=r){
int m=(l+r)/2;
change(l,m,1);
int door_use=tryCombination(arr_use);
rechange();
if(ans[i]){
if(door_use!=i)r=m-1;
else l=m+1;
}
else{
if(door_use!=i)l=m+1;
else r=m-1;
}
}
tut=go(l);
ans2[tut]=i;
kesin[tut]=1;
arr[tut]=ans[i];
for(int i=0;i<n;i++){
arr_use[i]=arr[i];
}
}
int anss[n];
for(int i=0;i<n;i++){
anss[i]=ans[ans2[i]];
}
answer(anss,ans2);
return ;
}