結果

問題 No.1 道のショートカット
ユーザー Takumi WatanabeTakumi Watanabe
提出日時 2024-03-16 10:58:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,605 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 191,288 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-16 10:58:57
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let n = read!(usize);
    let c = read!(usize);
    let _v = read!(usize);
    let ss = read!([usize]);
    let ts = read!([usize]);
    let ys = read!([usize]);
    let ms = read!([usize]);

    let max_time = 1000 * n;

    let mut v = ss
        .into_iter()
        .zip(ts.into_iter())
        .zip(ys.into_iter())
        .zip(ms.into_iter())
        .map(|(((s, t), y), m)| (s, t, y, m))
        .collect::<Vec<_>>();

    v.sort();

    let mut memo = vec![vec![max_time; c + 1]; n + 1];
    for y in 0..=c {
        memo[1][y] = 0;
    }
    for (s, t, y, m) in v.into_iter() {
        for sy in y..=c {
            let candidate = memo[s][sy] + m;
            for ty in 0..=(sy - y) {
                memo[t][ty] = memo[t][ty].min(candidate);
            }
        }
    }
    if memo[n][0] == max_time {
        println!("-1");
    } else {
        println!("{}", memo[n][0]);
    }
}
0