結果
問題 | No.971 いたずらっ子 |
ユーザー | uw_yu1rabbit |
提出日時 | 2021-03-14 01:33:47 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 1,517 bytes |
コンパイル時間 | 12,888 ms |
コンパイル使用メモリ | 377,264 KB |
実行使用メモリ | 53,248 KB |
最終ジャッジ日時 | 2024-11-07 11:49:25 |
合計ジャッジ時間 | 15,126 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#[allow(dead_code)] #[allow(unused_imports)] fn read<T: std::str::FromStr>() -> T { use std::io::*; let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } fn main(){ let h:usize = read(); let w:usize = read(); let t:Vec<String> = (0..h).map(|_| read()).collect(); let mut s = vec![Vec::new();h]; for i in 0..h { let tt:Vec<_> = t[i].chars().collect(); for j in 0..w { s[i].push(tt[j]); } } let mut dp = vec![vec![1e14 as i64;w];h]; dp[0][0] = 0; for i in 0..h { for j in 0..w { for k in [0,1].iter() { for l in [1,0].iter() { let ny = i + k; let nx = j + l; if ny >= h || nx >= w || k == l{ continue; }else{ if s[ny][nx] == 'k' { dp[ny][nx] = std::cmp::min(dp[ny][nx], dp[i][j] + 1 + (nx + ny) as i64); }else{ dp[ny][nx] = std::cmp::min(dp[ny][nx], dp[i][j] + 1); } } } } } } // println!("{:?}",dp); println!("{}", dp[h - 1][w - 1]); }