#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include "library.h"
using namespace std;
namespace {
int N;
const int MAXN = 1000;
vector<int> G[MAXN + 10];
vector<int> init(int l, int r, int i = -1) {
vector<int> v(N, 0);
fill(v.begin() + l, v.begin() + r + 1, 1);
if(i != -1) v[i] ^= 1;
return v;
}
map<tuple<int,int,int>,int> cnt;
int ask(int l, int r, int i = -1) {
int& res = cnt[{l,r,i}];
if(res == 0) res = Query(init(l, r, i));
return res;
}
void work(int i, int l, int r, int cc) {
if(l == r) {
G[i].push_back(l);
G[l].push_back(i);
return;
}
int m = (l + r) / 2;
if(cc == 1) {
if(ask(0, m) >= ask(0, m, i)) {
work(i, l, m, 1);
} else work(i, m+1, r, 1);
} else {
bool lYes = ask(0, m) >= ask(0, m, i);
bool rYes = ask(m+1, N-1) <= ask(m+1, N-1, i);
if(lYes) {
work(i, l, m, cc - int(rYes));
}
if(rYes) {
work(i, m+1, r, cc - int(lYes));
}
}
}
};
void Solve(int N_) {
N = N_;
for(int i = 1; i < N; i++) {
if(ask(0, i-1) >= ask(0, i)) {
int cc = ask(0, i-1) == ask(0, i) ? 1 : 2;
work(i, 0, i-1, cc);
}
}
for(int i = 0; i < N; i++) {
G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
}
vector<int> res;
res.reserve(N);
int u = 0, p = -1;
while(G[u].size() > 1) u++;
while((int)res.size() < N) {
res.push_back(u+1);
for(int v : G[u]) {
if(v != p) {
p = u;
u = v;
break;
}
}
}
Answer(res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
376 KB |
Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
376 KB |
Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |