Submission #761249

#TimeUsernameProblemLanguageResultExecution timeMemory
761249Dan4LifeLibrary (JOI18_library)C++17
0 / 100
31 ms344 KiB
#include <bits/stdc++.h> #include "library.h" using namespace std; #define pb push_back #define sz(a) (int)a.size() int n; vector<pair<int,int>> ed; vector<int> ans, adj[1500]; void dfs(int s, int p){ ans.pb(s); for(auto u : adj[s]) if(u!=p) dfs(u,s); } int chk(int l, int r, int q){ int ans = 0; for(auto [a,b] : ed) ans+=a>=l and b<=r; return r-l+1-q-ans; } void Solve(int N) { n = N; int tot = 0; vector<int> M(N,0); while(tot<n-1){ int l = 1, r = n, x = 1; while(l<r){ int mid = (l+r)/2; fill(begin(M),begin(M)+mid,1); int e = chk(1,mid,Query(M)); if(e>0) r=mid, x=e; else l=mid+1; fill(begin(M),begin(M)+mid,0); } int i = l; while(x--){ tot++; l = 1, r=i-1; while(l<r){ int mid = (l+r+1)/2; fill(begin(M)+mid-1,begin(M)+i,1); if(chk(mid,i,Query(M))>0) l=mid; else r=mid-1; fill(begin(M)+mid-1,begin(M)+i,0); } adj[i].pb(l), adj[l].pb(i), ed.pb({l,i}); } } for(int i = 1; i <= N; i++){ if(sz(adj[i])==1){ dfs(i,-1), Answer(ans); return; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...