Submission #675975

#TimeUsernameProblemLanguageResultExecution timeMemory
675975uroskMeetings (JOI19_meetings)C++14
100 / 100
630 ms920 KiB
#include "meetings.h"
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
#define maxn 2005
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n;
ll ask(ll x,ll y,ll z){
    return Query(x,y,z);
}
void ans(ll x,ll y){
    if(x>y) swap(x,y);
    Bridge(x,y);
}
ll xcur;
bool cmp(ll x,ll y){
    return ask(xcur,x,y)==x;
}
void reshi(vector<ll> v){
    ll n = sz(v);
    if(n<=1) return;
    if(n==2){ans(v[0],v[1]);return;}
    shuffle(all(v),rng);
    ll x = v[0],y = v[1];
    map<ll,vector<ll> > mp;
    mp[x].pb(x); mp[y].pb(y);
    for(ll i = 2;i<n;i++){
        ll z = v[i];
        ll u = ask(x,y,z);
        mp[u].pb(z);
    }
    vector<ll> w;
    w.pb(x);
    for(auto it : mp) if(it.fi!=x&&it.fi!=y) w.pb(it.fi);
    w.pb(y);
    xcur = x;
    sort(w.begin()+1,w.end()-1,cmp);
    for(ll i = 1;i<sz(w);i++) ans(w[i],w[i-1]);
    for(auto it : mp) reshi(it.sc);
}
void Solve(int N) {
  n = N;
  vector<ll> v(n);
  iota(all(v),0);
  reshi(v);
}
/*
5
0 1
0 2
1 3
1 4
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...