結果

問題 No.1199 お菓子配り-2
ユーザー phsplsphspls
提出日時 2020-09-05 21:06:12
言語 Rust
(1.72.1)
結果
AC  
実行時間 44 ms / 1,000 ms
コード長 751 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 138,688 KB
実行使用メモリ 4,948 KB
最終ジャッジ日時 2023-08-19 13:04:45
合計ジャッジ時間 7,834 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 11 ms
4,384 KB
testcase_04 AC 27 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 18 ms
4,376 KB
testcase_09 AC 11 ms
4,384 KB
testcase_10 AC 3 ms
4,948 KB
testcase_11 AC 9 ms
4,508 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 18 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 32 ms
4,376 KB
testcase_21 AC 20 ms
4,380 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 15 ms
4,380 KB
testcase_24 AC 21 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 23 ms
4,376 KB
testcase_27 AC 20 ms
4,380 KB
testcase_28 AC 43 ms
4,380 KB
testcase_29 AC 44 ms
4,376 KB
testcase_30 AC 42 ms
4,376 KB
testcase_31 AC 42 ms
4,376 KB
testcase_32 AC 44 ms
4,376 KB
testcase_33 AC 42 ms
4,376 KB
testcase_34 AC 40 ms
4,380 KB
testcase_35 AC 41 ms
4,376 KB
testcase_36 AC 41 ms
4,380 KB
testcase_37 AC 41 ms
4,376 KB
testcase_38 AC 42 ms
4,384 KB
testcase_39 AC 42 ms
4,508 KB
testcase_40 AC 42 ms
4,376 KB
testcase_41 AC 41 ms
4,376 KB
testcase_42 AC 41 ms
4,376 KB
testcase_43 AC 42 ms
4,376 KB
testcase_44 AC 41 ms
4,376 KB
testcase_45 AC 42 ms
4,376 KB
testcase_46 AC 42 ms
4,380 KB
testcase_47 AC 40 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::max;

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<i64> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        let mut tempa = String::new();
        std::io::stdin().read_line(&mut tempa).ok();
        let tempa: i64 = tempa.trim().split_whitespace().map(|s| s.parse::<i64>().unwrap()).sum::<i64>();
        a.push(tempa);
    }

    let mut dp: Vec<Vec<i64>> = vec![vec![0; n as usize + 1]; 2];
    for i in 0..(n as usize) {
        dp[0][i+1] = max(dp[0][i], dp[1][i] + a[i]);
        dp[1][i+1] = max(dp[1][i], dp[0][i] - a[i]);
    }
    println!("{}", dp[0][n as usize]);
}
0