Submission #45177

#TimeUsernameProblemLanguageResultExecution timeMemory
45177ikura355Library (JOI18_library)C++14
19 / 100
2074 ms1384 KiB
#include "library.h" #include<bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int n; int tree[maxn*4]; vector<int> vec; vector<int> way[maxn]; vector<int> ans; void build(int pos, int l, int r) { if(l>r) return ; tree[pos] = Query(vec); // printf("build %d: %d %d = %d\n",pos,l,r,tree[pos]); if(l==r) return ; int mid = (l+r)/2; for(int i=mid+1;i<=r;i++) vec[i-1] = 0; build(pos<<1,l,mid); for(int i=mid+1;i<=r;i++) vec[i-1] = 1; for(int i=l;i<=mid;i++) vec[i-1] = 0; build(pos<<1|1,mid+1,r); for(int i=l;i<=mid;i++) vec[i-1] = 1; } void link(int pos, int l, int r, int x) { if(l>r || x<=l) return ; vec[x-1] = 1; // printf("link [%d, %d] : %d\n",l,r,Query(vec)); if(Query(vec) > tree[pos]) return ; if(l==r) { // printf("----- link %d : %d\n",l,x); way[l].push_back(x); way[x].push_back(l); return ; } int mid = (l+r)/2; for(int i=mid+1;i<=r;i++) vec[i-1] = 0; link(pos<<1,l,mid,x); for(int i=mid+1;i<=r;i++) vec[i-1] = 1; for(int i=l;i<=mid;i++) vec[i-1] = 0; link(pos<<1|1,mid+1,r,x); for(int i=l;i<=mid;i++) vec[i-1] = 1; } void dfs(int u, int last) { ans.push_back(u); for(auto v : way[u]) { if(v==last) continue; dfs(v, u); } } void Solve(int N) { n = N; for(int i=1;i<=n;i++) vec.push_back(1); build(1,1,n); // if(n>200) return ; if(n==1) { Answer({1}); return ; } for(int i=1;i<=n;i++) link(1,1,n,i); for(int i=1;i<=n;i++) { if(way[i].size()==1) { dfs(i, 0); Answer(ans); return ; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...