結果

問題 No.971 いたずらっ子
ユーザー akakimidoriakakimidori
提出日時 2020-01-17 22:21:15
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 13,020 ms
コンパイル使用メモリ 379,112 KB
実行使用メモリ 52,864 KB
最終ジャッジ日時 2024-11-07 11:31:32
合計ジャッジ時間 14,981 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let h: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<Vec<char>> = it.map(|s| s.chars().collect()).collect();
    let mut dp = vec![vec![std::usize::MAX / 2; w]; h];
    dp[0][0] = 0;
    for i in 0..h {
        for j in 0..w {
            let cost = if s[i][j] == '.' {1} else {1 + i + j};
            if i > 0 {
                dp[i][j] = std::cmp::min(dp[i][j], dp[i - 1][j] + cost);
            }
            if j > 0 {
                dp[i][j] = std::cmp::min(dp[i][j], dp[i][j - 1] + cost);
            }
        }
    }
    let ans = dp[h - 1][w - 1];
    println!("{}", ans);
}

fn main() {
    run();
}
0