結果

問題 No.971 いたずらっ子
ユーザー akakimidoriakakimidori
提出日時 2020-01-17 22:21:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 157,568 KB
実行使用メモリ 52,992 KB
最終ジャッジ日時 2024-04-25 02:02:07
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
52,864 KB
testcase_01 AC 71 ms
52,736 KB
testcase_02 AC 54 ms
40,064 KB
testcase_03 AC 59 ms
52,992 KB
testcase_04 AC 56 ms
49,920 KB
testcase_05 AC 62 ms
52,864 KB
testcase_06 AC 48 ms
41,344 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 17 ms
15,232 KB
testcase_09 AC 15 ms
14,720 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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