結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー atcoder8atcoder8
提出日時 2022-09-04 14:02:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 14,515 ms
コンパイル使用メモリ 379,340 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-04-29 14:16:05
合計ジャッジ時間 16,797 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 33 ms
17,664 KB
testcase_08 AC 39 ms
17,664 KB
testcase_09 AC 39 ms
17,664 KB
testcase_10 AC 40 ms
17,664 KB
testcase_11 AC 39 ms
17,536 KB
testcase_12 AC 35 ms
17,664 KB
testcase_13 AC 36 ms
17,664 KB
testcase_14 AC 37 ms
17,664 KB
testcase_15 AC 38 ms
17,664 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 37 ms
17,536 KB
testcase_21 AC 37 ms
17,536 KB
testcase_22 AC 34 ms
17,664 KB
testcase_23 AC 34 ms
17,664 KB
testcase_24 AC 34 ms
17,664 KB
testcase_25 AC 38 ms
17,024 KB
testcase_26 AC 38 ms
17,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let (h, w) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse::<usize>().unwrap(),
            iter.next().unwrap().parse::<usize>().unwrap(),
        )
    };
    let mut aaa = vec![];
    for _ in 0..h {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        aaa.push(
            line.split_whitespace()
                .map(|x| x.parse::<usize>().unwrap())
                .collect::<Vec<_>>(),
        );
    }

    let mut dp = vec![vec![vec![0; 2]; w]; h];
    dp[0][0][0] = aaa[0][0];

    for i in 0..h {
        for j in 0..w {
            if i > 0 {
                if dp[i - 1][j][0] > aaa[i][j] {
                    dp[i][j][0] = dp[i][j][0].max(dp[i - 1][j][0] + aaa[i][j]);
                } else if (i, j) != (h - 1, w - 1) {
                    dp[i][j][1] = dp[i][j][1].max(dp[i - 1][j][0]);
                }

                if dp[i - 1][j][1] > aaa[i][j] {
                    dp[i][j][1] = dp[i][j][1].max(dp[i - 1][j][1] + aaa[i][j]);
                }
            }

            if j > 0 {
                if dp[i][j - 1][0] > aaa[i][j] {
                    dp[i][j][0] = dp[i][j][0].max(dp[i][j - 1][0] + aaa[i][j]);
                } else if (i, j) != (h - 1, w - 1) {
                    dp[i][j][1] = dp[i][j][1].max(dp[i][j - 1][0]);
                }

                if dp[i][j - 1][1] > aaa[i][j] {
                    dp[i][j][1] = dp[i][j][1].max(dp[i][j - 1][1] + aaa[i][j]);
                }
            }
        }
    }

    let reachable = dp[h - 1][w - 1].iter().any(|&x| x != 0);
    println!("{}", if reachable { "Yes" } else { "No" });
}
0