結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
|
提出日時 | 2022-11-23 16:21:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,663 bytes |
コンパイル時間 | 13,396 ms |
コンパイル使用メモリ | 384,412 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 20:18:07 |
合計ジャッジ時間 | 14,963 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 WA * 1 |
ソースコード
const INF: usize = 1usize << 60; fn main() { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let gx = temp[0]; let gy = temp[1]; let n = temp[2]; let f = temp[3]; let crystals = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let x = temp[0]; let y = temp[1]; let c = temp[2]; (x, y, c) }) .collect::<Vec<_>>(); let mut grid = vec![vec![vec![INF; gy+1]; gx+1]; 2]; grid[0][0][0] = 0; for idx in 0..n { let (ax, ay, c) = crystals[idx]; for used in 0..2 { for i in 0..=gx { for j in 0..=gy { if i+1 <= gx { grid[used][i+1][j] = grid[used][i+1][j].min(grid[used][i][j] + f); } if j+1 <= gy { grid[used][i][j+1] = grid[used][i][j+1].min(grid[used][i][j] + f); } if used == 0 && i+ax <= gx && j+ay <= gy { grid[1][i+ax][j+ay] = grid[1][i+ax][j+ay].min(grid[used][i][j] + c); } } } } for i in 0..=gx { for j in 0..=gy { grid[0][i][j] = grid[0][i][j].min(grid[1][i][j]); } } } println!("{}", grid[0][gx][gy].min(grid[1][gx][gy])); }