結果

問題 No.971 いたずらっ子
ユーザー akakimidoriakakimidori
提出日時 2020-01-17 22:21:15
言語 Rust
(1.72.1)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 146,772 KB
実行使用メモリ 52,956 KB
最終ジャッジ日時 2023-08-07 07:55:45
合計ジャッジ時間 3,023 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
52,956 KB
testcase_01 AC 83 ms
52,940 KB
testcase_02 AC 65 ms
41,244 KB
testcase_03 AC 70 ms
52,944 KB
testcase_04 AC 66 ms
50,228 KB
testcase_05 AC 70 ms
52,956 KB
testcase_06 AC 55 ms
42,400 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 20 ms
16,220 KB
testcase_09 AC 18 ms
14,740 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 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