結果

問題 No.2430 Damage Zone
ユーザー nautnaut
提出日時 2023-08-25 00:08:36
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 2,805 bytes
コンパイル時間 5,495 ms
コンパイル使用メモリ 159,264 KB
実行使用メモリ 18,084 KB
最終ジャッジ日時 2023-08-25 00:08:44
合計ジャッジ時間 5,307 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
10,564 KB
testcase_01 AC 13 ms
6,948 KB
testcase_02 AC 37 ms
16,968 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 38 ms
18,004 KB
testcase_15 AC 39 ms
18,084 KB
testcase_16 AC 38 ms
18,080 KB
testcase_17 AC 8 ms
5,112 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 16 ms
8,252 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 13 ms
6,368 KB
testcase_26 AC 18 ms
9,000 KB
testcase_27 AC 10 ms
5,584 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused `Result` that must be used
  --> Main.rs:72:5
   |
72 |     writeln!(out, "{}", ans);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
   = note: `#[warn(unused_must_use)]` on by default
   = note: this warning originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

ソースコード

diff #

#![allow(non_snake_case, unused_imports)]
use std::io::{self, prelude::*};
use std::str;

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    macro_rules! input {
        ($T: ty) => {
            scan.token::<$T>()
        };
        ($T: ty, $N: expr) => {
            (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>()
        };
    }

    const MOD: usize = 998_244_353;

    let H = input!(usize);
    let W = input!(usize);
    let K = input!(usize);

    let S = (0..H)
        .map(|_| input!(String).chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();

    let mut dp = vec![vec![vec![0; K]; W]; H];
    dp[0][0][0] = 1;

    for i in 0..H {
        for j in 0..W {
            for k in 0..K {
                // 右
                if j + 1 < W {
                    if S[i][j + 1] == '.' {
                        dp[i][j + 1][k] += dp[i][j][k];
                        dp[i][j + 1][k] %= MOD;
                    } else if S[i][j + 1] == 'o' {
                        if k + 1 < K {
                            dp[i][j + 1][k + 1] += dp[i][j][k];
                            dp[i][j + 1][k + 1] %= MOD;
                        }
                    }
                }

                // 下
                if i + 1 < H {
                    if S[i + 1][j] == '.' {
                        dp[i + 1][j][k] += dp[i][j][k];
                        dp[i + 1][j][k] %= MOD;
                    } else if S[i + 1][j] == 'o' {
                        if k + 1 < K {
                            dp[i + 1][j][k + 1] += dp[i][j][k];
                            dp[i + 1][j][k + 1] %= MOD;
                        }
                    }
                }

            }
        }
    }

    let mut ans = 0;

    for k in 0..K {
        ans += dp[H - 1][W - 1][k];
        ans %= MOD;
    }

    writeln!(out, "{}", ans);
}

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}
0