結果

問題 No.1199 お菓子配り-2
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-08-29 10:20:14
言語 Rust
(1.77.0)
結果
AC  
実行時間 119 ms / 1,000 ms
コード長 1,053 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 160,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 16:11:48
合計ジャッジ時間 7,700 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 29 ms
5,376 KB
testcase_04 AC 74 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 36 ms
5,376 KB
testcase_08 AC 49 ms
5,376 KB
testcase_09 AC 30 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 23 ms
5,376 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 46 ms
5,376 KB
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 47 ms
5,376 KB
testcase_19 AC 13 ms
5,376 KB
testcase_20 AC 81 ms
5,376 KB
testcase_21 AC 50 ms
5,376 KB
testcase_22 AC 29 ms
5,376 KB
testcase_23 AC 39 ms
5,376 KB
testcase_24 AC 53 ms
5,376 KB
testcase_25 AC 9 ms
5,376 KB
testcase_26 AC 62 ms
5,376 KB
testcase_27 AC 50 ms
5,376 KB
testcase_28 AC 116 ms
5,376 KB
testcase_29 AC 117 ms
5,376 KB
testcase_30 AC 117 ms
5,376 KB
testcase_31 AC 117 ms
5,376 KB
testcase_32 AC 117 ms
5,376 KB
testcase_33 AC 112 ms
5,376 KB
testcase_34 AC 118 ms
5,376 KB
testcase_35 AC 118 ms
5,376 KB
testcase_36 AC 119 ms
5,376 KB
testcase_37 AC 114 ms
5,376 KB
testcase_38 AC 118 ms
5,376 KB
testcase_39 AC 114 ms
5,376 KB
testcase_40 AC 115 ms
5,376 KB
testcase_41 AC 116 ms
5,376 KB
testcase_42 AC 119 ms
5,376 KB
testcase_43 AC 118 ms
5,376 KB
testcase_44 AC 117 ms
5,376 KB
testcase_45 AC 116 ms
5,376 KB
testcase_46 AC 118 ms
5,376 KB
testcase_47 AC 117 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::*`
 --> main.rs:2:5
  |
2 | use std::collections::*;
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let n:usize = read();
    let m:usize = read();
    let mut a:Vec<i64> = vec![0;n];
    for i in 0..n{
        let mut rec:i64 = 0;
        for _j in 0..m {
            let l:i64 = read();
            rec += l;
        }
        a[i] = rec;
    }
    let mut dp:Vec<Vec<i64>> = vec![vec![0;2];n];
    dp[0][0] = a[0];
    for i in 1..n{
        dp[i][0] = max(dp[i - 1][1] + a[i],dp[i - 1][0]);
        dp[i][1] = max(dp[i - 1][0] - a[i],dp[i - 1][1]);
    }
    let mut ans:i64 = 0;
    for i in 0..n{
        for j in 0..2{
            ans = max(ans,dp[i][j]);
        }
    }
    println!("{}",ans);
}
0