# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969517 | anango | Cave (IOI13_cave) | C++17 | 2 ms | 860 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>
using namespace std;
#define int long long
int tryvec(vector<int> v) {
int32_t attempt[v.size()];
for (int i=0; i<v.size(); i++) {
attempt[i] = v[i];
}
int T=tryCombination(attempt);
if (T==-1) {
return v.size();
}
return T;
}
void ansvec(vector<int> v, vector<int> w) {
int32_t attempt[v.size()];
int32_t perm[v.size()];
for (int i=0; i<v.size(); i++) {
attempt[i] = v[i];
perm[i] = w[i];
}
answer(attempt, perm);
}
void exploreCave(int32_t N) {
int n=N;
vector<int> permutation(n,-1);
vector<int> answers(n,-1);
vector<int> current(n,-1);
for (int cur=0; cur<N; cur++) {
//find if the intended state is off or on
current=vector<int>(n,0);
for (int i=0; i<n; i++) {
if (answers[i]!=-1) {
current[i] = answers[i];
}
}
int ans = tryvec(current);
int ist=-1;
if (ans==cur) {
//intended state is 1
ist=1;
int l=0;
int r=N;
while (l<r) {
int m=(l+r)/2;
for (int i=l; i<=m; i++) {
if (answers[i]==-1) {
current[i] = 1;
}
}
if (tryvec(current)==cur) {
l=m+1;
r=r;
}
else {
l=l;
r=m;
}
}
answers[l] = ist;
permutation[cur] = l;
}
else {
assert(ans==cur+1);
//intended state is 0
current=vector<int>(n,1);
for (int i=0; i<n; i++) {
if (answers[i]!=-1) {
current[i] = answers[i];
}
}
int l=0;
int r=N;
while (l<r) {
int m=(l+r)/2;
for (int i=l; i<=m; i++) {
if (answers[i]==-1) {
current[i] = 0;
}
}
if (tryvec(current)==cur) {
l=m+1;
r=r;
}
else {
l=l;
r=m;
}
}
ist=0;
answers[l] = ist;
permutation[cur] = l;
}
}
ansvec(answers, permutation);
}
Compilation message (stderr)
# | 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... |