結果

問題 No.1 道のショートカット
コンテスト
ユーザー h_noson
提出日時 2016-05-07 20:11:46
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,298 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,592 ms
コンパイル使用メモリ 178,028 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-08 16:06:27
合計ジャッジ時間 2,574 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

vector<int> e[50];
int dist[301][51];
int S[1500], T[1500], Y[1500], M[1500];

int main() {
    int i, j, N, C, V;
    priority_queue<tuple<int,int,int>> q; // (-time,to,cost)
    cin >> N >> C >> V;
    rep (i,V) cin >> S[i];
    rep (i,V) cin >> T[i];
    rep (i,V) cin >> Y[i];
    rep (i,V) cin >> M[i];
    rep (i,V) e[S[i]].push_back(i);
    rep (i,C+1) rep (j,N+1) dist[i][j] = INF;
    dist[0][1] = 0;
    q.push(make_tuple(0,1,0));
    while (!q.empty()) {
        int from = get<1>(q.top());
        int cost = get<2>(q.top());
        q.pop();
        for (auto x : e[from]) {
            int d = dist[cost][from] + M[x];
            int c = cost + Y[x];
            if (c <= C && dist[c][T[x]] > d) {
                dist[c][T[x]] = d;
                q.push(make_tuple(-d,T[x],c));
            }
        }
    }
    int ans = INF;
    rep (i,C+1) ans = min(ans,dist[i][N]);
    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}
0