이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "library.h"
using namespace std;
#define pb push_back
#define sz(v) ((int)v.size())
mt19937 rng(time(NULL));
vector<int> ans, j;
bitset<1001> in;
int query(int s, vector<int> &z) {
shuffle(z.begin(), z.end(), rng);
if (sz(z) == 1) {
fill(j.begin(), j.end(), 0);
j[s-1] = 1; j[z.back()-1] = 1;
if (Query(j) != 1)
return -1;
else
return z[0];
}
if (sz(z) == 0) return -1;
int l = 0;
int r = sz(z) - 1;
int c1, c2;
while (l < r) {
int m = (l+r)/2;
fill(j.begin(), j.end(), 0);
for (int i = l; i <= m; ++i)
j[z[i]-1] = 1;
c1 = Query(j);
j[s-1] = 1;
c2 = Query(j);
if (c1 >= c2)
r = m;
else
l = m+1;
}
if (l == sz(z) -1) {
fill(j.begin(), j.end(), 0);
j[s-1] = 1; j[z.back()-1] = 1;
if (Query(j) != 1)
return -1;
}
return z[l];
}
void remain(vector<int> &u, int n) {
u.clear();
for (int i = 1; i <= n; ++i)
if (!in[i]) u.pb(i);
}
void Solve(int n) {
int c = 1;
j.assign(n, 0);
vector<int> u;
while (c != -1) {
in[c] = 1;
ans.pb(c);
remain(u, n);
c = query(c, u);
}
reverse(ans.begin(), ans.end());
c = ans.back();
ans.pop_back();
while (c != -1) {
in[c] = 1;
ans.pb(c);
remain(u, n);
c = query(c, u);
}
Answer(ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |