이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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] = 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |