結果

問題 No.1199 お菓子配り-2
ユーザー fukafukatanifukafukatani
提出日時 2020-08-28 21:39:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 59 ms / 1,000 ms
コード長 1,278 bytes
コンパイル時間 6,080 ms
コンパイル使用メモリ 162,000 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-04-26 14:31:54
合計ジャッジ時間 7,129 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 16 ms
5,376 KB
testcase_04 AC 37 ms
6,784 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 19 ms
5,376 KB
testcase_08 AC 24 ms
5,376 KB
testcase_09 AC 16 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 12 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 25 ms
5,376 KB
testcase_19 AC 7 ms
5,376 KB
testcase_20 AC 43 ms
7,808 KB
testcase_21 AC 27 ms
5,760 KB
testcase_22 AC 15 ms
5,376 KB
testcase_23 AC 21 ms
5,376 KB
testcase_24 AC 29 ms
5,632 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 33 ms
6,272 KB
testcase_27 AC 26 ms
5,376 KB
testcase_28 AC 59 ms
9,856 KB
testcase_29 AC 59 ms
9,856 KB
testcase_30 AC 58 ms
9,600 KB
testcase_31 AC 56 ms
9,600 KB
testcase_32 AC 59 ms
9,600 KB
testcase_33 AC 56 ms
9,728 KB
testcase_34 AC 56 ms
9,728 KB
testcase_35 AC 59 ms
9,728 KB
testcase_36 AC 59 ms
9,728 KB
testcase_37 AC 58 ms
9,728 KB
testcase_38 AC 59 ms
9,728 KB
testcase_39 AC 59 ms
9,728 KB
testcase_40 AC 59 ms
9,728 KB
testcase_41 AC 58 ms
9,600 KB
testcase_42 AC 59 ms
9,728 KB
testcase_43 AC 59 ms
9,728 KB
testcase_44 AC 59 ms
9,600 KB
testcase_45 AC 59 ms
9,728 KB
testcase_46 AC 58 ms
9,728 KB
testcase_47 AC 58 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut a = vec![vec![0; m]; n];
    for i in 0..n {
        let v = read_vec::<i64>();
        for j in 0..m {
            a[i][j] += v[j];
        }
    }

    let a = a.iter().map(|x| x.iter().sum::<i64>()).collect::<Vec<_>>();

    let mut dp = vec![0; 2];
    dp[1] = -std::i64::MAX;
    for i in 0..n {
        dp[1] = max(dp[1], dp[0] + a[i]);
        if dp[1] != -std::i64::MAX {
            dp[0] = max(dp[0], dp[1] - a[i]);
        }
    }
    let ans = max(dp[0], dp[1]);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0