結果

問題 No.1 道のショートカット
ユーザー ShibuyapShibuyap
提出日時 2020-07-04 15:31:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,647 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 207,196 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2023-09-22 13:49:59
合計ジャッジ時間 7,087 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 6 ms
8,992 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 6 ms
9,120 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 5 ms
8,888 KB
testcase_16 RE -
testcase_17 AC 6 ms
8,876 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 13 ms
12,344 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 WA -
testcase_43 AC 5 ms
9,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
struct edge{ int to, cost; };
const int INF = 1001001001;
const int MAX_N = 200005;
const int MAX_V = 200005;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+MAX_V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int n, c, v;
    cin >> n >> c >> v;
    int s[v], t[v], y[v], m[v];
    rep(i,v){
        cin >> s[i] >> t[i] >> y[i] >> m[i];
        s[i]--; t[i]--;
    }
    rep(i,v){
        int from = s[i];
        int to = t[i];
        int cost = m[i];
        int money = y[i];
        rep(j,400){
            if(j - money < 0)continue;
            edge e;
            e.to = to * 400 + (j - money);
            e.cost = cost;
            G[from*400 + j].push_back(e);
        }
    }

    dijkstra(c);

    int ans = 1001001001;
    rep(i,400)ans = min(ans, d[(n-1)*400+i]);
    if(ans >= INF)ans = -1;
    cout << ans << endl;
    return 0;
}

0