結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー koba-e964koba-e964
提出日時 2022-05-20 22:54:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,215 bytes
コンパイル時間 4,109 ms
コンパイル使用メモリ 181,824 KB
実行使用メモリ 7,676 KB
最終ジャッジ日時 2023-10-20 13:45:28
合計ジャッジ時間 6,112 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 0 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 30 ms
7,676 KB
testcase_08 AC 57 ms
7,676 KB
testcase_09 AC 57 ms
7,676 KB
testcase_10 AC 57 ms
7,676 KB
testcase_11 AC 56 ms
7,676 KB
testcase_12 AC 38 ms
7,676 KB
testcase_13 AC 38 ms
7,676 KB
testcase_14 AC 39 ms
7,676 KB
testcase_15 AC 38 ms
7,676 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 41 ms
7,676 KB
testcase_21 AC 40 ms
7,676 KB
testcase_22 AC 32 ms
7,676 KB
testcase_23 AC 33 ms
7,676 KB
testcase_24 AC 33 ms
7,676 KB
testcase_25 AC 53 ms
7,412 KB
testcase_26 AC 55 ms
7,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

fn main() {
    input! {
        h: usize, w: usize,
        a: [[i64; w]; h],
    }
    let mut dp = vec![vec![[0; 2]; w]; h];
    dp[0][0][0] = a[0][0];
    for i in 0..h {
        for j in 0..w {
            for b in 0..2 {
                let val = dp[i][j][b];
                if i < h - 1 {
                    let x = a[i + 1][j];
                    if val > x {
                        dp[i + 1][j][b].chmax(val + x);
                    } else if b == 0 {
                        dp[i + 1][j][1].chmax(val);
                    }
                }
                if j < w - 1 {
                    let x = a[i][j + 1];
                    if val > x {
                        dp[i][j + 1][b].chmax(val + x);
                    } else if b == 0 {
                        dp[i][j + 1][1].chmax(val);
                    }
                }
            }
        }
    }
    println!("{}", if max(dp[h - 1][w - 1][0], dp[h - 1][w - 1][1]) > a[h - 1][w - 1] {
        "Yes"
    } else {
        "No"
    });
}
0