#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
void Solve(int N){
vector <int> res(N), M(N), used(N), a(N), b(N);
int cur = 0, p1 = 0;
a[0] = 0;
b[0] = 0;
used[0] = 1;
while(1){
vector <int> v;
for(int i = 0; i < N; i ++)
if(!used[i])
v.emplace_back(i);
if(!v.size()) break;
int lo = 0, hi = v.size() - 1;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
for(int i = 0; i <= md; i ++){
M[v[i]] = 1;
}
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A == B)
hi = md;
else
lo = md;
M[cur] = 0;
for(int i = 0; i <= md; i ++)
M[v[i]] = 0;
}
for(int i = 0; i <= lo; i ++)
M[v[i]] = 1;
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A == B) hi = lo;
M[v[hi]] = 1;
M[cur] = 0;
A = Query(M);
M[cur] = 1;
B = Query(M);
if(A != B) break;
M[cur] = 0;
for(int i = 0; i <= hi; i ++)
M[v[i]] = 0;
used[v[hi]] = 1;
a[++ p1] = v[hi];
cur = v[hi];
}
cur = 0;
int p2 = 0;
while(1){
vector <int> v;
for(int i = 0; i < N; i ++)
if(!used[i])
v.emplace_back(i);
if(!v.size()) break;
int lo = 0, hi = v.size() - 1;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
for(int i = 0; i <= md; i ++){
M[v[i]] = 1;
}
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A == B)
hi = md;
else
lo = md;
M[cur] = 0;
for(int i = 0; i <= md; i ++)
M[v[i]] = 0;
}
for(int i = 0; i <= lo; i ++)
M[v[i]] = 1;
int A = Query(M);
M[cur] = 1;
int B = Query(M);
if(A == B) hi = lo;
M[v[hi]] = 1;
M[cur] = 0;
A = Query(M);
M[cur] = 1;
B = Query(M);
if(A != B) break;
M[cur] = 0;
for(int i = 0; i <= hi; i ++)
M[v[i]] = 0;
used[v[hi]] = 1;
b[++ p2] = v[hi];
cur = v[hi];
}
int ps = 0;
for(int i = p2; i > 0; i --){
res[ps ++] = b[i] + 1;
}
for(int i = 0; i <= p1; i ++){
res[ps ++] = a[i] + 1;
}
Answer(res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |