# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1231035 | rhm_gan | 동굴 (IOI13_cave) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
const int N = 5001;
bool is[N];
int s[N], d[N];
int a[N];
void exploreCave(int n) {
for (int j = 0; j < n; j++) {
for (int i = 0; i < MXN; i++) {
a[i] = (is[i] ? s[i] : 1);
}
int res = tryCombination(a);
if (res == -1) res = n + 1;
int k = (res > j);
int l = -1, r = n;
while (l + 1 < r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) {
a[i] = (is[i] ? s[i] : k);
}
for (int i = m + 1; i < n; i++) {
a[i] = (is[i] ? s[i] : 1 - k);
}
int x = tryCombination(a);
if (x == -1) x = n + 1;
if (x > j) {
r = m;
}
else {
l = m;
}
}
is[r] = 1;
s[r] = k;
d[r] = j;
}
answer(s, d);
}