結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー akakimidoriakakimidori
提出日時 2022-05-20 21:57:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 2,939 bytes
コンパイル時間 4,450 ms
コンパイル使用メモリ 164,564 KB
実行使用メモリ 12,508 KB
最終ジャッジ日時 2023-10-20 12:32:46
合計ジャッジ時間 5,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 0 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 19 ms
10,708 KB
testcase_08 AC 24 ms
12,508 KB
testcase_09 AC 24 ms
12,508 KB
testcase_10 AC 25 ms
12,508 KB
testcase_11 AC 24 ms
12,244 KB
testcase_12 AC 20 ms
11,484 KB
testcase_13 AC 20 ms
11,484 KB
testcase_14 AC 21 ms
11,484 KB
testcase_15 AC 20 ms
11,484 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 27 ms
11,220 KB
testcase_21 AC 27 ms
11,220 KB
testcase_22 AC 17 ms
10,956 KB
testcase_23 AC 18 ms
10,956 KB
testcase_24 AC 20 ms
10,956 KB
testcase_25 AC 27 ms
11,716 KB
testcase_26 AC 29 ms
12,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fn main() {
    run();
}

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
0