結果

問題 No.1 道のショートカット
コンテスト
ユーザー T1610
提出日時 2026-10-31 23:43:03
言語 Rust
(1.99.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 5,000 ms
+ 604µs
コード長 1,098 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,896 ms
コンパイル使用メモリ 190,128 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-10-31 23:43:15
合計ジャッジ時間 6,821 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(unused_imports)]
use ac_library::{ModInt998244353 as mint, Segtree, dsu, modint};
use itertools::{Itertools, izip};
use num::Float;
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};
use std::{
    cmp::Reverse,
    collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet},
};

// #[fastout]
fn main() {
    input! {
        n : usize,
        c : usize,
        m : usize,
        s : [Usize1; m],
        t : [Usize1; m],
        x : [usize; m],
        y : [i64; m],
    }
    let es = izip!(s, t, x, y).collect_vec();
    let g = es.iter().fold(vec![vec![]; n], |mut acc, &(u, v, x, y)| {
        acc[u].push((v, x, y));
        acc
    });
    let inf = 1e18 as i64;
    let mut dp = vec![vec![inf; c + 1]; n];
    dp[0][c] = 0;
    for i in 0..n {
        for &(to, x, y) in &g[i] {
            for j in x..=c {
                let mi = dp[to][j - x].min(dp[i][j] + y);
                dp[to][j - x] = mi;
            }
        }
    }
    let mut ans = *dp[n - 1].iter().min().unwrap();
    if ans == inf {
        ans = -1;
    }
    println!("{}", ans);
}
0