# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995077 | otarius | Library (JOI18_library) | C++17 | 33 ms | 344 KiB |
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 ff first
#define sc second
#define pb push_back
#define pii pair<int, int>
void Solve(int n) {
vector<int> ans(n);
vector<int> v(n, 1);
bool used[n + 1] = {};
for (int i = 1; i <= n; i++) {
v[i - 1] = 0;
if (Query(v) == 1) {
ans[0] = i; used[i] = 1; break;
} v[i - 1] = 1;
}
for (int i = 2; i < n; i++) {
vector<int> cur;
for (int j = 1; j <= n; j++)
if (!used[j]) cur.pb(j);
int l = 0, r = cur.size() - 1, m, an;
while (l <= r) {
m = (l + r) / 2;
for (int &k : v) k = 0;
v[ans[i - 2] - 1] = 1;
for (int k = 0; k <= m; k++)
v[cur[k] - 1] = 1;
int vl = Query(v);
v[ans[i - 2] - 1] = 0;
if (Query(v) == vl) {
an = m; r = m - 1;
} else l = m + 1;
} ans[i - 1] = cur[an]; used[cur[an]] = 1;
} for (int i = 1; i <= n; i++)
if (!used[i]) ans[n - 1] = i;
Answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |