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[]);
pii recur(int res, int l, int r, vector<int>&v, int ans[]){
if(l == r){
return {v[l], res};
}
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(res2 > res){
return recur(res, l, m, v, ans);
} else if(res2 == res){
return recur(res2, m+1, r, v, ans);
} else if(res2 < res){
for(int i = l; i <= m; i++){
ans[v[i]] ^= 1;
}
return recur(res2, l, m, v, ans);
}
}
void exploreCave(int N){
int ans[N], d[N];
memset(ans, 0, sizeof(ans));
memset(d, -1, sizeof(d));
vector<int> v(N);
iota(v.begin(), v.end(), 0);
while(SZ(v)){
pii p = recur(tryCombination(ans), 0, SZ(v) - 1, v, ans);
d[p.ff] = p.ss;
ans[p.ff] ^= 1;
v.erase(find(v.begin(), v.end(), p.ff));
}
answer(ans, d);
}
Compilation message (stderr)
cave.cpp: In function 'std::pair<int, int> recur(int, int, int, std::vector<int>&, int*)':
cave.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
37 | }
| ^
# | 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... |