結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2024-03-16 10:58:50 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 32 ms / 5,000 ms |
コード長 | 1,605 bytes |
コンパイル時間 | 12,371 ms |
コンパイル使用メモリ | 378,300 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 03:54:36 |
合計ジャッジ時間 | 14,254 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#[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]);}}