제출 #729053

#제출 시각아이디문제언어결과실행 시간메모리
729053groguShortcut (IOI16_shortcut)C++14
0 / 100
2082 ms47284 KiB
#include "shortcut.h" #include <bits/stdc++.h> #define endl '\n' #define here cerr<<"=========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #define ll long long #define pb push_back #define popb pop_back #define all(a_) a_.begin(),a_.end() #define pll pair<ll,ll> #define sc second #define fi first #define llinf 1000000000000000LL #define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;} using namespace std; #define maxn 2000005 ll n,c,tsz; vector<pll> g[maxn]; ll dis[maxn]; ll naj(ll x){ for(ll i = 0;i<=tsz;i++) dis[i] = llinf; dis[x] = 0; priority_queue<pll> pq; pq.push({0,x}); while(pq.size()){ ll u = pq.top().sc; ll cur = -pq.top().fi; pq.pop(); if(cur!=dis[u]) continue; for(pll p : g[u]){ ll s = p.fi; ll w = p.sc; if(cur+w<dis[s]){ dis[s] = cur+w; pq.push({-dis[s],s}); } } } ll ans = 1; for(ll i = 1;i<=tsz;i++) if(dis[i]>dis[ans]) ans = i; return ans; } ll find_shortcut(int N, vector<int> L, vector<int> D, int C) { n = N; tsz = n; c = C; for(ll i = 1;i<n;i++){ g[i].pb({i+1,L[i-1]}); g[i+1].pb({i,L[i-1]}); } for(ll i = 1;i<=n;i++) if(D[i-1]){ g[i].pb({++tsz,D[i-1]}); g[tsz].pb({i,D[i-1]}); } ll ans = llinf; for(ll i = 1;i<=n;i++){ for(ll j = i+1;j<=n;j++){ g[i].pb({j,c}); g[j].pb({i,c}); ll cur = 0; for(ll k = 1;k<=tsz;k++){ ll f = naj(k); cur = max(cur,dis[f]); } ans = min(ans,cur); g[i].popb(); g[j].popb(); } } return ans; } /** 4 10 10 20 20 0 40 0 30 9 30 10 10 10 10 10 10 10 10 20 0 30 0 0 40 0 40 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...