// Author: caption_mingle
#include "bits/stdc++.h"
#include "library.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
int query(vector<int> a, int n) {
vector<int> vec(n, 0);
for(int x : a) {
vec[x - 1] = 1;
}
return Query(vec);
}
void Solve(int n) {
if(n == 1) {
Answer({1});
return;
}
vector<int> cand;
for(int i = 1; i <= n; i++) {
cand.pb(i);
}
vector<int> ans;
for(int i = 0; i < sz(cand); i++) {
vector<int> a;
int x = cand[i];
for(int j = 1; j <= n; j++) {
if(j == x) continue;
a.pb(j);
}
if(query(a, n) == 1) {
ans.pb(x);
cand.erase(cand.begin() + i);
break;
}
}
for(int i = 2; i <= n; i++) {
int l = 0, r = sz(cand) - 1;
int nxt = 0;
while(l <= r) {
int m = (l + r) >> 1;
vector<int> que;
for(int j = 0; j <= m; j++) que.pb(cand[j]);
int t1 = query(que, n);
for(int x : ans) que.pb(x);
int t2 = query(que, n);
if(t1 == t2) {
r = m - 1;
nxt = m;
} else l = m + 1;
}
ans.pb(cand[nxt]);
cand.erase(cand.begin() + nxt);
}
Answer(ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |