제출 #411463

#제출 시각아이디문제언어결과실행 시간메모리
411463BlagojceMeetings (JOI19_meetings)C++17
100 / 100
765 ms1360 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1e9+7; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t z; const int mxn = 2e5+5; #include "meetings.h" /* void bridge(int a, int b){ cout<<"bridge : "<<a<<"-"<<b<<endl; } int Query(int a, int b, int c){ cout<<a<<' '<<b<<' '<<c<<endl; int d; cin >> d; return d; }*/ int cpr[mxn]; vector<int> Sort(vector<int> v, int l, int r){ if((int)v.size() <= 1) return v; int pivot = v[_rand()%(int)v.size()]; vector<int> L; vector<int> R; for(auto u : v){ if(u == pivot) continue; int q = Query(l, u, pivot); if(q == u){ L.pb(u); } else{ R.pb(u); } } L = Sort(L, l, pivot); R = Sort(R, pivot, r); v.clear(); for(auto u : L) v.pb(u); v.pb(pivot); for(auto u : R) v.pb(u); return v; } void bridge(int a, int b){ Bridge(min(a,b), max(a,b)); } void solve(vector<int> v){ sort(all(v)); v.erase(unique(all(v)), v.end()); int m = (int)v.size(); if(m <= 1) return; if(m == 2){ bridge(v[0], v[1]); return; } int a = _rand()%m; int b = _rand()%(m-1); if(b >= a) ++b; a = v[a]; b = v[b]; vector<int> g[m]; fr(i, 0, m){ cpr[v[i]] = i; g[i].pb(v[i]); } vector<int> diam; fr(i, 0, m){ if(v[i] == a || v[i] == b) continue; int q = Query(a, b, v[i]); g[cpr[q]].pb(v[i]); if(q != a && q != b) diam.pb(q); } sort(all(diam)); diam.erase(unique(all(diam)), diam.end()); diam = Sort(diam, a, b); diam.insert(diam.begin(), a); diam.pb(b); fr(i, 0, (int)diam.size()-1){ bridge(diam[i], diam[i+1]); } fr(i, 0, m){ solve(g[i]); } } void Solve(int N){ vector<int> v; fr(i, 0, N) v.pb(i); solve(v); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...