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 "library.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n;
vector<int> vec;
vector<int> way[maxn];
vector<int> ans;
int ask(int l, int r, int x) {
for(int i=l;i<=r;i++) vec[i-1] = 1;
if(x) vec[x-1] = 1;
int temp = Query(vec);
for(int i=l;i<=r;i++) vec[i-1] = 0;
if(x) vec[x-1] = 0;
return temp;
}
void addedge(int x, int l, int r) {
if(l>r) return ;
// printf("ask [%d, %d] : %d = %d original = %d\n",l,r,x,ask(l,r,x),ask(l,r,0));
if(ask(l,r,x)>ask(l,r,0)) return ;
if(l==r) {
// printf("%d <-> %d\n",l,x);
way[x].push_back(l);
way[l].push_back(x);
return ;
}
int mid = (l+r)/2;
addedge(x,l,mid); addedge(x,mid+1,r);
}
void dfs(int u, int last) {
// printf("dfs %d\n",u,last);
ans.push_back(u);
for(auto v : way[u]) {
if(v==last) continue;
dfs(v, u);
}
}
void Solve(int N) {
if(N==1) {
Answer({1});
return ;
}
n = N;
for(int i=0;i<n;i++) vec.push_back(0);
for(int x=1;x<=n;x++) addedge(x,1,x-1);
for(int x=1;x<=n;x++) {
if(way[x].size()==1) {
dfs(x, 0);
Answer(ans);
return ;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |