# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
204705 | bogdan_ogorodniy | 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 <bits/stdc++.h>
#include "cave.h"
using namespace std;
const int N = 5 * 1e3 + 1;
const int inf = 1e9 + 7;
vector <int> sett(vector <int> s, vector <int> fnd, int pos, int f) {
vector <int> temp = s;
for (int i = 0; i < pos; i++) {
if (!fnd[i]) {
temp[i] = f;
}
}
for (int i = pos; i < s.size(); i++) {
if (!fnd[i]) {
temp[i] = !f;
}
}
return temp;
}
void exploreCave(int n) {
vector <int> s(n, 0);
vector <int> p(n, 0);
vector <int> fnd(n, 0);
for (int i = 0; i < n; i++) {
// find the switch connected with i-th door
// find the switch position 1/0
int k = tryCombination(sett(s, fnd, n, 1));
// in (fnd) -- already used swithces
bool f = 0;
if (k >= i + 1) {
f = true;
}
else {
f = false;
}
int l = 0,
r = n - 1;
while (r - l > 1) {
int m = (l + r) / 2;
int k = tryCombination(sett(s, fnd, m + 1, f));
if (k >= i + 1) {
r = m;
}
else {
l = m + 1;
}
}
k = tryCombination(sett(s, fnd, l + 1, f));
if (k >= i + 1) {
p[l] = i;
s[l] = f;
fnd[l] = true;
}
else {
p[r] = i;
s[r] = f;
fnd[r] = true;
}
}
int S[n], P[n];
for (int i = 0; i < n; i++) {
S[i] = s[i];
P[i] = p[i];
}
answer(S, P);
}
// signed main() {
// return 0;
// }