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;
void Solve(int N) {
if (N == 1) {
Answer({1});
return;
}
if (N == 2) {
Answer({1, 2});
return;
}
vector<int> cc[N];
for (int i = 0; i < N; i++) {
cc[i].resize(N);
iota(cc[i].begin(), cc[i].end(), 0);
cc[i].erase(find(cc[i].begin(), cc[i].end(), i));
}
vector<int> adj[N];
auto findBest = [&](int i) {
int lo = 0, hi = cc[i].size();
while (lo < hi) {
int mid = lo + hi >> 1;
vector<int> vec(N);
for (int j = 0; j <= mid; j++) {
vec[cc[i][j]] = 1;
}
int q = Query(vec);
vec[i] = 1;
q - Query(vec) < 0 ? lo = mid + 1 : hi = mid;
}
if (lo == cc[i].size()) return -1;
int j = cc[i][lo];
adj[i].push_back(j);
adj[j].push_back(i);
cc[j].erase(find(cc[j].begin(), cc[j].end(), i));
cc[i].erase(find(cc[i].begin(), cc[i].end(), j));
return j;
};
for (int cur = 0; cur >= 0; cur = findBest(cur));
for (int cur = 0; cur >= 0; cur = findBest(cur));
for (int i = 0; i < N; i++) {
if (adj[i].size() < 2) {
vector<int> ans(N);
ans[0] = i;
for (int j = 1, x = adj[i][0]; j < N; j++) {
ans[j] = x;
for (int k : adj[x]) {
x = k == ans[j-1] ? x : k;
}
}
for (int &j : ans) {
j++;
}
Answer(ans);
return;
}
}
}
Compilation message (stderr)
library.cpp: In lambda function:
library.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int mid = lo + hi >> 1;
| ~~~^~~~
library.cpp:35:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (lo == cc[i].size()) return -1;
| ~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |