結果

問題 No.971 いたずらっ子
ユーザー phsplsphspls
提出日時 2022-12-28 01:40:27
言語 Rust
(1.77.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 4,669 ms
コンパイル使用メモリ 150,092 KB
実行使用メモリ 49,176 KB
最終ジャッジ日時 2023-08-14 15:54:51
合計ジャッジ時間 8,812 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 214 ms
49,064 KB
testcase_01 AC 214 ms
49,132 KB
testcase_02 AC 157 ms
37,432 KB
testcase_03 AC 162 ms
49,176 KB
testcase_04 AC 146 ms
46,252 KB
testcase_05 AC 160 ms
49,112 KB
testcase_06 AC 124 ms
38,436 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 40 ms
14,296 KB
testcase_09 AC 36 ms
13,760 KB
testcase_10 AC 1 ms
4,384 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,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 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::collections::VecDeque;


const INF: usize = 1usize << 60;

fn main() {
    let mut hw = String::new();
    std::io::stdin().read_line(&mut hw).ok();
    let hw: Vec<usize> = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let h = hw[0];
    let w = hw[1];
    let grid = (0..h).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.chars().collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut result = vec![vec![INF; w]; h];
    result[0][0] = 0;
    let mut deque = VecDeque::new();
    deque.push_back((0, 0));
    while let Some((x, y)) = deque.pop_front() {
        if x + 1 < h {
            let next_val = result[x][y] + 1 + if grid[x+1][y] == 'k' { x + y + 1 } else { 0 };
            if result[x+1][y] > next_val {
                result[x+1][y] = next_val;
                deque.push_back((x+1, y));
            }
        }
        if y + 1 < w {
            let next_val = result[x][y] + 1 + if grid[x][y+1] == 'k' { x + y + 1 } else { 0 };
            if result[x][y+1] > next_val {
                result[x][y+1] = next_val;
                deque.push_back((x, y+1));
            }
        }
    }
    println!("{}", result[h-1][w-1]);
}
0