# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303917 | rocks03 | Cave (IOI13_cave) | C++14 | 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 "cave.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int) (x).size())
using namespace std;
void answer(int S[], int D[]);
int tryCombination(int S[]);
int recur(int res, int l, int r, vector<int>&v, int ans[]){
if(l == r){
return v[l];
}
int m = (l + r) / 2;
for(int i = l; i <= m; i++){
ans[v[i]] ^= 1;
}
int res2 = tryCombination(ans);
for(int i = l; i <= m; i++){
ans[v[i]] ^= 1;
}
if(res != res2){
return recur(res, l, m, v, ans);
} else{
return recur(res, m+1, r, v, ans);
}
}
void exploreCave(int N){
int ans[N], d[N];
memset(ans, 0, sizeof(ans));
memset(d, -1, sizeof(d));
while(true){
vector<int> v;
for(int i = 0; i < N; i++){
if(d[i] == -1){
v.pb(i);
}
}
if(!SZ(v)) break;
int res = tryCombination(ans);
if(res == -1) break;
int get = recur(res, 0, SZ(v) - 1, v, ans);
d[get] = res;
ans[get] ^= 1;
}
for(int i = 0; i < N; i++){
if(d[i] == -1){
ans[i] ^= 1;
d[i] = tryCombination(ans);
ans[i] ^= 1;
}
}
answer(ans, d);
}