結果

問題 No.1 道のショートカット
ユーザー tabataba
提出日時 2024-07-31 15:59:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,420 bytes
コンパイル時間 13,486 ms
コンパイル使用メモリ 388,168 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-31 16:00:06
合計ジャッジ時間 14,972 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::collections::BTreeSet;

fn main() {
    proconio::input! {
        n: u64,
        c: u64,
        v: u64,
        s: [u64; v],
        t: [u64; v],
        y: [u64; v],
        m: [u64; v],
    }

    let goal = n - 1;
    let s = s.into_iter().map(|s| s - 1).collect::<Vec<_>>();
    let t = t.into_iter().map(|t| t - 1).collect::<Vec<_>>();
    let mut stym = s
        .into_iter()
        .zip(t.into_iter())
        .zip(y.into_iter())
        .zip(m.into_iter())
        .map(|(((s, t), y), m)| (s, t, y, m))
        .collect::<Vec<_>>();
    stym.sort_unstable();

    let mut moves = BTreeSet::new();
    moves.insert((0, 0, 0));
    let mut mtime_min = u64::MAX;
    loop {
        let mut new_moves = BTreeSet::new();
        moves.into_iter().for_each(|(town, cost, mtime)| {
            stym.iter()
                .filter(|(s, _, y, _)| *s == town && cost + y <= c)
                .for_each(|(_, t, y, m)| {
                    if *t == goal {
                        mtime_min = std::cmp::min(mtime_min, m + mtime);
                    } else if mtime + m <= mtime_min {
                        new_moves.insert((*t, cost + y, mtime + m));
                    }
                });
        });
        moves = new_moves;
        if moves.is_empty() {
            break;
        }
    }
    if mtime_min == u64::MAX {
        println!("-1");
    } else {
        println!("{mtime_min}");
    }
}
0