# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
160042 | combi1k1 | Library (JOI18_library) | C++14 | 2 ms | 376 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"
using namespace std;
int ask(vector<int> v) { return v.size() == 1 ? 1 : Query(v); }
int Connected(int u,vector<int> v) {
int a = ask(v); v.push_back(u);
int b = ask(v); return a >= b;
}
vector<int> g[1001];
void Solve(int n) {
for(int i = 1 ; i <= n ; ++i) {
vector<int> v;
int x = i;
int y = 0;
if (g[i].size()) y = g[i][0];
for(int j = 1 ; j <= n ; ++j) if (j != x && j != y)
v.push_back(j);
int l = 0;
int r = v.size();
for(; l < r ;) {
int m = (l + r) / 2;
if (Connected(i,vector<int>(v.begin() + l,v.begin() + m + 1)))
r = m;
else
l = m + 1;
}
if (l < v.size()) {
x = v[l];
g[i].push_back(x);
g[x].push_back(i);
}
}
vector<int> res;
for(int i = 1 ; i <= n ; ++i) if (g[i].size() == 1) {
int x = i;
res.push_back(0);
for(int j = 0 ; j < n ; ++j)
for(int u : g[x]) if (u != res.back()) {
res.push_back(x);
x = u; break;
}
res.push_back(x);
res.erase(res.begin());
Answer(res); break;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |