結果

問題 No.1 道のショートカット
ユーザー kappybar
提出日時 2020-06-21 18:01:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 1,670 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 179,276 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-07-20 16:50:10
合計ジャッジ時間 3,217 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int n = 55 * 305;
int m;
vector<vector<pll>> graph(n,vector<pll>());

vector<ll>  Dijkstra(int start){
    vector<bool> seen(55 * 305,false);
    vector<ll> shortest(55 * 305,LINF);
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push(pll(0,start));

    while(!pq.empty()){
        ll dist = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(seen[node]) continue;

        shortest[node] = dist;
        seen[node] = true;

        for(pll next:graph[node]){
            int next_node = next.second;
            ll next_cost = next.first;
            if(seen[next_node]) continue;
            pq.push(pll(next_cost + dist,next_node));
        }
    }

    return shortest;
}

int main(){
    cin >> n;
    int c;
    cin >> c;
    cin >> m;
    vector<int> a(m),b(m),y(m),t(m);
    rep(i,m) cin >> a[i],--a[i];
    rep(i,m) cin >> b[i],--b[i];
    rep(i,m) cin >> y[i];
    rep(i,m) cin >> t[i];
    rep(i,m){
        for(int j=y[i];j<=300;j++){
            graph[a[i]*301+j].push_back(pll(t[i],b[i]*301+j-y[i]));
            //graph[b[i]*301+j].push_back(pll(t[i],a[i]*301+j-y[i]));
        }
    }

    vector<ll> answer = Dijkstra(0 + c);
    ll ans = LINF;
    rep(i,c+1){
        ans = min(ans,answer[(n-1)*301+i]);
    }
    if(ans==LINF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0