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 "library.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
void Solve(int n) {
vector<int> q(n, 1), res(n, -1), done(n, 0);
int end = -1;
REP (i, 0, n) {
q[i] = 0;
if (Query(q) == 1) {
end = i;
break;
}
q[i] = 1;
}
res[0] = end;
done[end] = 1;
REP (i, 1, n) {
vector<int> useful;
REP (j, 0, n) if (!done[j]) useful.pb(j);
int lo = 0, hi = useful.size() - 1, mid;
while (lo < hi) {
mid = lo + hi + 1 >> 1;
REP (j, 0, n) q[j] = 0;
REP (j, 0, mid) q[useful[j]] = 1;
q[res[i - 1]] = 1;
int with = Query(q);
q[res[i - 1]] = 0;
int without = Query(q);
if (with == without) {
hi = mid - 1;
} else {
lo = mid;
}
}
res[i] = useful[hi];
done[useful[hi]] = 1;
}
REP (i, 0, n) res[i]++;
Answer(res);
}
Compilation message (stderr)
library.cpp: In function 'void Solve(int)':
library.cpp:26:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | mid = lo + hi + 1 >> 1;
| ~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |