#include <cstdio>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void Solve(int N){
vector<int> M(N);
vector<int> res(N);
deque<deque<int>> curr;
vector<bool> rem(N+1,0);
curr.push_back({1});
int prev = 1;
M[0] = 1;
vector<int> pick;
for(int i=2;i<=N;i++){
pick.push_back(i);
}
random_shuffle(pick.begin(),pick.end());
for(int x=2;x<=N;x++){
int i = pick[x-2];
M[i-1] = 1;
int q = Query(M);
if(q > prev){
curr.push_back({i});
prev = q;
}else{
vector<int> side;
for(int c=0;c<(int)curr.size();c++){
if(rem[c])continue;
vector<int> m(N);
m[i-1] = 1;
for(auto cc:curr[c])m[cc-1] = 1;
if(Query(m) == 1)side.push_back(c);
}
vector<int> m(N);
m[i-1] = 1;
for(auto cc:curr[side[0]])m[cc-1] = 1;
bool pos = 0;
if(curr[side[0]].size() > 1){
m[curr[side[0]].back()-1] = 0;
int q = Query(m);
m[curr[side[0]].back()-1] = 1;
if(q == 1){
curr[side[0]].push_front(i);
}else{
pos = 1;
curr[side[0]].push_back(i);
}
}else{
curr[side[0]].push_front(i);
}
if((int)side.size() == 2){
curr.push_back(deque<int>());
int c = curr[side[1]].front(),d = curr[side[1]].back();
if(pos){
m[c-1] = 1;
q = Query(m);
for(auto cc:curr[side[0]])curr.back().push_back(cc);
if(q == 1){
for(auto cc:curr[side[1]])curr.back().push_back(cc);
}else
{
reverse(curr[side[1]].begin(),curr[side[1]].end());
for(auto cc:curr[side[1]])curr.back().push_back(cc);
}
}else{
m[d-1] = 1;
q = Query(m);
if(q == 1){
for(auto cc:curr[side[1]])curr.back().push_back(cc);
for(auto cc:curr[side[0]])curr.back().push_back(cc);
}else{
reverse(curr[side[1]].begin(),curr[side[1]].end());
for(auto cc:curr[side[1]])curr.back().push_back(cc);
for(auto cc:curr[side[0]])curr.back().push_back(cc);
}
}
rem[side[1]] = 1;
rem[side[0]] = 1;
curr[side[1]].clear();
curr[side[0]].clear();
prev--;
}
}
for(int c=0;c<(int)curr.size();c++){
if(!rem[c]){
for(auto j:curr[c]){
cout << j<<" ";
}
cout << '\n';
}
}
//cout<<"out\n";
}
res = vector<int>(curr.back().begin(),curr.back().end());
Answer(res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
200 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
200 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |