제출 #753355

#제출 시각아이디문제언어결과실행 시간메모리
753355Dan4LifeMeetings (JOI19_meetings)C++17
100 / 100
636 ms2796 KiB
#include <bits/stdc++.h> #include "meetings.h" using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a),end(a) const int mxN = (int)2e3+10; int n, used[mxN]; vector<int> S[mxN]; void mergeSort(vector<int> &v, int a, int b){ if(sz(v)<=1) return; int mid = sz(v)/2; vector<int> w,x; w.clear(), x.clear(); for(int i = 0; i < mid; i++) w.pb(v[i]); for(int i = mid; i < sz(v); i++) x.pb(v[i]); mergeSort(w,a,b), mergeSort(x,a,b); v.clear(); int i = 0, j = 0; while(i<sz(w) and j<sz(x)){ if(Query(a,w[i],x[j])==w[i]) v.pb(w[i++]); else v.pb(x[j++]); } while(i<sz(w)) v.pb(w[i++]); while(j<sz(x)) v.pb(x[j++]); } void bridge(int a, int b){ if(a>b) swap(a,b); return Bridge(a,b); } void recur(int a, vector<int> SS){ if(SS.empty()) return; auto itr = SS.begin(); int r = rand()%sz(SS); while(r--) itr++; int b = *itr; used[a]=used[b]=1; vector<int> path; path.clear(); vector<int> S[n+1]; for(int i = 0; i < n; i++) S[i].clear(); for(auto i : SS){ if(!used[i]){ int x = Query(a,b,i); if(x==i) path.pb(i),used[i]=1; else S[x].pb(i); } } mergeSort(path,a,b); if(path.empty()) bridge(a,b); else bridge(a,path[0]),bridge(path.back(),b); for(int i = 0; i < sz(path)-1; i++) bridge(path[i],path[i+1]); for(auto u : path) recur(u,S[u]); recur(a,S[a]); recur(b,S[b]); } void Solve(int N) { n = N; vector<int> v; for(int i = 1; i < n; i++) S[0].pb(i); recur(0,S[0]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...