Submission #173959

#TimeUsernameProblemLanguageResultExecution timeMemory
173959CaroLindaRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
1054 ms152016 KiB
#include "railroad.h" #include <bits/stdc++.h> #define debug printf #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define ff first #define ss second #define pb push_back #define mk make_pair #define ll long long #define sz size() #define pii pair<int,int> #define all(x) x.begin(),x.end() #define tiii tuple<int,int,int> #define mkt make_tuple const int MAX = 1114112 + 10 ; const ll inf = 1e18+10 ; using namespace std ; bool isOn(int m, int bit) { return ( (1<<bit)&m ) != 0 ; } int setOff(int m, int bit) { return ( m^(1<<bit) ) ; } vector< pii > adj[MAX] ; int n ; ll d[MAX] ; inline void dijkstra() { priority_queue< pair<ll,int> , vector< pair<ll,int> > , greater< pair<ll,int> > > fila ; lp(i,0,MAX) d[i] = inf ; lp(i,0,n) { fila.push( mk( 0LL , i * (1<<n) ) ) ; d[i*(1<<n)] = 0LL ; } while( !fila.empty() ) { int cur = fila.top().ss ; ll dis = fila.top().ff ; fila.pop() ; if( dis != d[cur] ) continue ; for(auto p : adj[cur] ) if( d[p.ff] > dis + p.ss ) { d[p.ff] = dis + p.ss ; fila.push( mk( d[p.ff] , p.ff ) ) ; } } } long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { n = (int) s.size(); lp(i,0,n) for(int m = 0 ; m < (1<<n) ; m++ ) lp(j,0,n) { if( j == i || isOn(m,j) ) continue ; adj[i*(1<<n) + m ].pb( mk( j*(1<<n) + (m|(1<<i)) , max(0, t[i]-s[j] ) ) ) ; } dijkstra() ; ll minDist = inf ; lp(i,0,n) minDist = min( minDist, d[i*(1<<n) + setOff( (1<<n)-1 ,i)] ) ; return minDist ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...