# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1203897 | andrejikus | Cave (IOI13_cave) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
//#include "cave.h"
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
const int N = 5003;
int s[N], d[N];
int tryCombination(int S[]);
void answer(int S[], int D[]);
void exploreCave(int n) {
for (int i = 0; i < n; i++) d[i] = -1;
auto ok = [&](int l, int r) {
for (int k = l; k <= r; k++) {
if (d[k] != -1) continue;
s[k] = 0;
}
int x = tryCombination(s);
for (int k = l; k <= r; k++) {
if (d[k] != -1) continue;
s[k] = 1;
}
int y = tryCombination(s);
return (x != y);
};
for (int i = 0; i < n; i++) {
int low = 0, high = n-1;
while (low < high) {
int mid = (low + high) / 2;
if (ok(low, mid))
high = mid;
else
low = mid+1;
}
d[i] = low;
s[i] = 0;
int x = tryCombination(s);
if (x == low)
s[i] = 1;
}
answer(s, d);
}
int main() {
int N = 3;
exploreCave(N);
return 0;
}