# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107217 | SecretAgent007 | 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>
using namespace std;
#include "cave.h"
#define int long long
const int INF = 1e18;
///////////////////////////////////////////////////
/*
vector< int > input;
vector< int > openWith;
int n;
int tryCombination(vector< int > given){
cout << "TRY ";
for(int a : given) cout << a << ' ';
cout << endl;
for(int i = 0; i < n; i++){
if(input[openWith[i]] != given[openWith[i]]){
cout << "REP " << i << endl;
return i;
}
}
cout << "REP " << -1 << endl;
return -1;
}
void answer(vector< int > S, vector< int > D){
for(int a : S) cout << a << ' ';
cout << endl;
if(S != input){
cout << "NO S" << endl;
return;
}
for(int i = 0; i < n; i++){
if(i != D[openWith[i]]){
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
*/
///////////////////////////////////////////////////
vector< int > known;
vector< int > v;
void flip(int a, int b){
for(int i = a; i <= b; i++){
if(known[i] != -1) v[i] = known[i];
else if(v[i] == 0) v[i] = 1;
else v[i] = 0;
}
}
int interrupt;
bool type;
vector< int > D;
void query(int l, int r, int door, bool greater){
//cout << "Query " << l << ' ' << r << ' ' << door << ' ' << greater << endl;
if(l == r){
interrupt = l;
if(greater){
type = v[l];
}else{
if(v[l]) type = 0;
else type = 1;
}
return;
}
int mid = (l+r)/2;
if(greater){
flip(l,mid);
int re = tryCombination(v);
if(re == -1) re = INF;
if(re > door){
query(mid+1,r,door,1);
}else{
query(l,mid,door,0);
}
}else{
flip(l,mid);
int re = tryCombination(v);
if(re == -1) re = INF;
if(re > door){
query(l,mid,door,1);
}else{
query(mid+1,r,door,0);
}
}
}
void exploreCave(int N){
known.assign(N,-1);
v.assign(N,0);
D.resize(N);
bool verif;
vector< int > S(N);
for(int i = 0; i < N; i++){
fill(v.begin(), v.end(), 1);
flip(0,N-1);
int r = tryCombination(v);
if(r == -1 || r > i) verif = true;
else verif = false;
query(0,N-1,i,verif);
D[interrupt] = i;
known[interrupt] = type;
S[interrupt] = type;
}
answer(S,D);
}
/*
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
input.resize(n);
openWith.resize(n);
for(int i = 0; i < n; i++){
cin >> input[i];
}
for(int i = 0; i < n; i++){
cin >> openWith[i];
}
exploreCave(n);
}
*/