# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566658 | two_sides | Library (JOI18_library) | C++17 | 38 ms | 208 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 <bits/stdc++.h>
#include "library.h"
namespace {
using namespace std;
const int N = 1005;
int nxt[N][2];
void add_edge(int i, int j) {
if (nxt[i][0]) nxt[i][1] = j;
else nxt[i][0] = j;
if (nxt[j][0]) nxt[j][1] = i;
else nxt[j][0] = i;
}
}
void Solve(int n) {
for (int i = 1; i <= n; i++) {
vector<int> p;
if (nxt[i][1]) continue;
for (int j = 1; j <= n; j++)
if (j != i && j != nxt[i][0])
p.push_back(j);
int lo = 0, hi = p.size();
while (lo < hi) {
int mi = (lo + hi) / 2;
vector<int> q(n);
for (int j = 0; j <= mi; j++)
q[p[j] - 1] = 1;
int tmp = Query(q); q[i - 1] = 1;
if (Query(q) > tmp) lo = mi + 1;
else hi = mi;
}
if (hi < p.size()) add_edge(i, p[hi]);
}
vector<int> ans(1, 1);
while (nxt[ans[0]][1]) ans[0]++;
for (int i = 0; i + 1 < n; i++) {
if (i == 0 || nxt[ans[i]][0] != ans[i - 1])
ans.push_back(nxt[ans[i]][0]);
else ans.push_back(nxt[ans[i]][1]);
}
Answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |