# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
648877 | JANCARAPAN | 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 "cave.h"
#include <bits/stdc++.h>
using namespace std;
// int tryCombination(int a[4]) {
// int ans = 0;
// if (a[2] == 1) {
// ans++;
// if (a[1] == 1) {
// ans++;
// if (a[3] == 0) {
// ans++;
// if (a[0] == 1) {
// ans++;
// }
// }
// }
// }
// return ans;
// }
void exploreCave(int n) {
int pos[n], con[n], used[n];
for (int i=0; i<n; i++) {
// per a cada porta faig bs dels interruptors
int l = 0, r = n - 1;
int res = n - 1;
bool on = (tryCombination(pos) == i);
while (l <= r) {
int m = l + (r - l) / 2;
bool can = 0;
//bool all = 0;
for (int j=l; j<=m; j++) {
if (used[j]) continue;
pos[j] = 1;
//all = 1;
}
// for (auto x : pos) cerr << x << " ";
// cerr << endl;
if (tryCombination(pos) >= i + 1 && on) {
can = 1;
}
//can &= all;
for (int j=l; j<=m; j++) {
if (used[j]) continue;
pos[j] = 0;
}
if (can) {
r = m - 1;
res = m;
} else {
l = m + 1;
}
//cerr << m << " " << l << " " << r << endl;
}
//cerr << "res: " << res << endl;
used[res] = 1;
pos[res] = on;
con[res] = i;
}
answer(pos, con);
// for (auto x : pos) cout << x << " ";
// cout << endl << endl;
// for (auto x : con) cout << x <<" ";
// cout << endl;
}
// int main() {
// exploreCave(4);
// }