結果

問題 No.971 いたずらっ子
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2021-03-14 01:33:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,517 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 166,912 KB
実行使用メモリ 53,248 KB
最終ジャッジ日時 2024-04-25 02:17:27
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
53,248 KB
testcase_01 AC 123 ms
53,248 KB
testcase_02 AC 96 ms
44,416 KB
testcase_03 AC 95 ms
53,248 KB
testcase_04 AC 92 ms
50,304 KB
testcase_05 AC 92 ms
53,120 KB
testcase_06 AC 74 ms
43,520 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 26 ms
15,232 KB
testcase_09 AC 26 ms
14,848 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 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 1 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 #

#[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]);
}
0