Submission #380287

#TimeUsernameProblemLanguageResultExecution timeMemory
380287Pichon5Shortcut (IOI16_shortcut)C++17
0 / 100
3 ms620 KiB
#include "shortcut.h" #include<bits/stdc++.h> #define lcm(a,b) (a/__gcd(a,b))*b #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long int #define vi vector<int> #define vll vector<ll> #define pb push_back #define F first #define S second #define mp make_pair //salida rapida "\n" //DECIMALES fixed<<sp(n)<<x<<endl; //gcd(a,b)= ax + by //lCB x&-x //set.erase(it) - ersases the element present at the required index//auto it = s.find(element) //set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end() //set.lower_bound(element) - iterator pointing to element greater than or equal to the given element //set.upper_bound(element) - iterator pointing to element greater than the given element // | ^ //__builtin_popcount(x) using namespace std; long long find_shortcut(int n, vi l, vi d, int c){ vector<vector<pair<int,ll> > >G(25,vector<pair<int,ll> >()); vector<bool>vis; vector<bool>ok(26,false); for(int i=0;i<n-1;i++){ G[i].pb({i+1,l[i]}); G[i+1].pb({i,l[i]}); } for(int i=0;i<n;i++){ ok[i]=1; if(d[i]==0)continue; ok[i+10]=1; G[10+i].pb({i,d[i]}); G[i].pb({10+i,d[i]}); } ll res=1e16; for(int i=0;i<n;i++){ for(int l=i+1;l<n;l++){ int a=i,b=l; ll diametro=0ll; for(int j=0;j<25;j++){ if(!ok[j])continue; priority_queue<pair<ll,int> >q; vll dis(24,1e16); dis[j]=0ll; q.push({0,j}); vis.assign(24,false); while(!q.empty()){ int u=q.top().S; q.pop(); if(vis[u])continue; vis[u]=1; if(u==a){ if(dis[u]+c<=dis[b]){ dis[b]=dis[u]+c; q.push({-dis[b],b}); } } if(u==b){ if(dis[u]+c<=dis[a]){ dis[a]=dis[u]+c; q.push({-dis[a],a}); } } for(auto it : G[u]){ if(dis[u]+it.S<dis[it.F]){ dis[it.F]=dis[u]+it.S; q.push({-dis[it.F],it.F}); } } } ll ma=0ll; for(int k=0;k<25;k++){ if(ok[k])ma=max(ma,dis[k]); } diametro=max(diametro, ma); } res=min(diametro,res); } } return res; //9 30 10 10 10 10 10 10 10 10 20 0 30 0 0 40 0 40 0 //4 10 10 20 20 0 40 0 30 }
#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...