結果

問題 No.1 道のショートカット
ユーザー tonyu0
提出日時 2019-12-03 08:54:49
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,521 bytes
コンパイル時間 25,495 ms
コンパイル使用メモリ 378,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:44:31
合計ジャッジ時間 15,324 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;
fn main() {
    // input
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let c: usize = itr.next().unwrap().parse().unwrap();
    let v: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<usize> = (0..v)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let t: Vec<usize> = (0..v)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let y: Vec<usize> = (0..v)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let m: Vec<u32> = (0..v)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut g: Vec<Vec<(usize, usize, u32)>> = vec![Vec::new(); n + 1];
    for i in 0..v {
        g[s[i] - 1].push((t[i] - 1, y[i], m[i]));
    }

    // calc
    let inf: u32 = 100000;
    let mut dp: Vec<Vec<u32>> = vec![vec![inf; 606]; n];
    dp[0][0] = 0;
    for i in 0..n {
        for j in 0..g[i].len() {
            let nv = g[i][j].0;
            let ny = g[i][j].1;
            let nm = g[i][j].2;
            for py in 0..301 {
                dp[nv][py + ny] = std::cmp::min(dp[nv][py + ny], dp[i][py] + nm);
            }
        }
    }
    let mut ans: u32 = inf;
    for i in 0..c + 1 {
        ans = std::cmp::min(ans, dp[n - 1][i]);
    }
    if ans == inf {
        println!("-1");
    } else {
        print!("{}", ans);
    }
}
0