結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-03 13:46:53 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,507 bytes |
| コンパイル時間 | 19,826 ms |
| コンパイル使用メモリ | 376,724 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:43:47 |
| 合計ジャッジ時間 | 15,067 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
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
const INF: u32 = 100_000;
let mut dp: Vec<Vec<u32>> = vec![vec![INF; 606]; n];
dp[0][0] = 0;
for i in 0..n {
for &j in g[i].iter() {
let nv = j.0;
let ny = j.1;
let nm = j.2;
for cy in 0..301 {
dp[nv][cy + ny] = std::cmp::min(dp[nv][cy + ny], dp[i][cy] + 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 {
println!("{}", ans);
}
}