This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//IOI 2013
#include "cave.h"
#include<bits/stdc++.h>
using namespace std;
int ask(int m, int good, int n, vector<int>& x, int comb[], int connect[]){
int ask[n];
for(int i=0; i<n; i++){
ask[i] = comb[i];
}
for(int i=0; i<=m; i++){
comb[x[i]] = good;
}
for(int i=m+1; i<(int)x.size(); i++){
comb[x[i]] = 1-good;
}
return tryCombination(ask);
}
void exploreCave(int N) {
const int n=N;
vector<int> x(n);
iota(x.begin(), x.end(), 0);
int comb[n];
int connect[n];
for(int i=0; i<n; i++){
comb[i] = 0;
connect[i] = -1;
}
for(int i=0; i<n; i++){
int door = tryCombination(comb);
int good=0;
if(door == i){
good = 1;
}
int l=0; int r=x.size()-1;
int ans=0;
while(l<=r){
int m=l+(r-l)/2;
int door = ask(m, good, n, x, comb, connect);
if(door == -1 || i < door){
ans = m;
r = m-1;
}
else{
l = m+1;
}
}
assert(x[ans] == i);
comb[x[ans]] = good;
connect[x[ans]] = i;
x.erase(x.begin() + ans);
}
answer(comb, connect);
}
# | 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... |