結果

問題 No.1199 お菓子配り-2
ユーザー akakimidoriakakimidori
提出日時 2020-08-28 21:50:56
言語 Rust
(1.77.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 2,227 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 160,128 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-04-26 14:43:38
合計ジャッジ時間 7,115 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 17 ms
6,528 KB
testcase_04 AC 41 ms
13,328 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 21 ms
7,424 KB
testcase_08 AC 28 ms
9,600 KB
testcase_09 AC 16 ms
6,656 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 13 ms
5,504 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 27 ms
9,344 KB
testcase_17 AC 13 ms
5,504 KB
testcase_18 AC 29 ms
9,600 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 50 ms
15,820 KB
testcase_21 AC 31 ms
10,368 KB
testcase_22 AC 16 ms
6,272 KB
testcase_23 AC 23 ms
8,192 KB
testcase_24 AC 31 ms
10,368 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 34 ms
11,776 KB
testcase_27 AC 29 ms
9,728 KB
testcase_28 AC 63 ms
20,352 KB
testcase_29 AC 63 ms
20,352 KB
testcase_30 AC 65 ms
20,352 KB
testcase_31 AC 65 ms
20,480 KB
testcase_32 AC 63 ms
20,352 KB
testcase_33 AC 65 ms
20,352 KB
testcase_34 AC 63 ms
20,480 KB
testcase_35 AC 63 ms
20,352 KB
testcase_36 AC 65 ms
20,480 KB
testcase_37 AC 65 ms
20,352 KB
testcase_38 AC 63 ms
20,352 KB
testcase_39 AC 64 ms
20,352 KB
testcase_40 AC 65 ms
20,352 KB
testcase_41 AC 64 ms
20,480 KB
testcase_42 AC 64 ms
20,224 KB
testcase_43 AC 65 ms
20,352 KB
testcase_44 AC 65 ms
20,352 KB
testcase_45 AC 65 ms
20,352 KB
testcase_46 AC 66 ms
20,352 KB
testcase_47 AC 64 ms
20,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ---------- begin chmin, chmax ----------
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 ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
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_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_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")
    };
}

//

fn run() {
    input! {
        h: usize,
        w: usize,
        a: [[i64; w]; h],
    }
    let mut b = vec![];
    for a in a {
        b.push(a.iter().sum::<i64>());
    }
    let mut dp = (0, std::i64::MIN / 2);
    for b in b {
        let (x, y) = dp;
        dp.0.chmax(y - b);
        dp.1.chmax(x + b);
    }
    let ans = std::cmp::max(dp.0, dp.1);
    println!("{}", ans);
}

fn main() {
    run();
}
0