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;
const int MXn = 5005;
int n;
int ask(int a[]) {
int res = tryCombination(a);
if (res < 0) res = n;
return res;
}
int ans[MXn], arr[MXn], pos[MXn]; bool ok[MXn];
void exploreCave(int N) {
n = N;
memset(ans, 0, sizeof ans);
for (int i = 0; i < N; i++) {
int t = tryCombination(ans) == i ? 0 : 1;
int l = 0, r = N - 1, mid, res;
while (l <= r) {
mid = (l + r) >> 1;
for (int i = 0; i < N; i++) {
if (ok[i]) arr[i] = ans[i];
else if (i <= mid) arr[i] = 1;
}
int tmp = ask(arr);
if (t) {
if (tmp == i) {
res = mid;
r = mid - 1;
} else l = mid + 1;
} else {
if (tmp > i) {
res = mid;
r = mid - 1;
} else l = mid + 1;
}
for (int i = 0; i < N; i++) {
if (ok[i]) arr[i] = ans[i];
else if (i <= mid) arr[i] = 0;
}
}
ok[res] = true;
ans[res] = t ^ 1;
pos[res] = i;
}
answer(ans, pos);
}
Compilation message (stderr)
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:46:18: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | pos[res] = i;
| ~~~~~~~~~^~~
# | 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... |