#ifndef SUN
#include "cave.h"
#endif // SUN
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
//int numAsk = 0;
//int s[5050], d[5050];
//int correct[5050];
int numAsk = 0;
int ask(int val, int n, int s[], int correct[]) {
++numAsk;
for (int i = 0; i < n; ++i) {
if (correct[i]) s[i] = 0;
else s[i] = (i <= val) ^ 1;
}
return tryCombination(s);
}
void exploreCave(int n) {
int s[n], d[n], correct[n];
for (int i = 0; i < n; ++i) d[i] = i, s[i] = 0;
REP(i, n) correct[i] = 0;
numAsk = 0;
for (int step = 0; step < n; ++step) {
int l = 0, r = n - 1, g, vt = -1;
while (l <= r) {
g = (l + r) >> 1;
int get = ask(g, n, s, correct);
if (get == -1 || get >= step + 1) vt = g, r = g - 1;
else l = g + 1;
}
d[step] = vt;
correct[vt] = 1;
}
assert(numAsk <= 70000);
answer(s, d);
}
| # | 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... |