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 "grader.cpp"
#include "library.h"
#define pb push_back
#define ok cerr << "OK\n";
using namespace std;
const int NN = 1e3 + 7;
bool used[NN];
void Solve(int N) {
vector < int > M(N, 0);
vector < int > ans, vv;
deque < int > dq;
int n = N;
int cnt = 0;
M[0] = 1;
dq.pb(0);
used[0] = 1;
for (int i = 1; i < n; i++) {
M[i] = 1;
int qq = Query(M);
if (qq == 1) {
cnt++;
vv.pb(i);
}
M[i] = 0;
}
M[0] = 0;
used[vv[0]] = 1;
dq.push_front(vv[0]);
if (cnt == 2) {
dq.push_back(vv[1]);
used[vv[1]] = 1;
}
vv.clear();
cnt++;
while (cnt < n) {
bool fl = 1;
M[dq.back()] = 1;
for (int j = 0; j < n; j++) {
if (used[j]) continue;
M[j] = 1;
int qq = Query(M);
M[j] = 0;
if (qq == 1) {
fl = 0;
M[dq.back()] = 0;
dq.pb(j);
M[dq.back()] = 1;
used[j] = 1;
cnt++;
break;
}
}
M[dq.back()] = 0;
if (fl) break;
}
while (cnt < n) {
bool fl = 1;
M[dq.front()] = 1;
for (int j = 0; j < n; j++) {
if (used[j]) continue;
M[j] = 1;
int qq = Query(M);
M[j] = 0;
if (qq == 1) {
fl = 0;
M[dq.front()] = 0;
dq.push_front(j);
M[dq.front()] = 1;
used[j] = 1;
cnt++;
break;
}
}
if (fl) break;
}
// cerr << dq.size() << endl;
for (int to : dq) {
// cerr << to << ' ';
ans.pb(to + 1);
}
Answer(ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |