結果

問題 No.2889 Rusk
ユーザー atcoder8atcoder8
提出日時 2024-09-13 22:32:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 14,172 ms
コンパイル使用メモリ 376,496 KB
実行使用メモリ 28,800 KB
最終ジャッジ日時 2024-09-13 22:33:17
合計ジャッジ時間 17,792 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 10 ms
6,144 KB
testcase_16 AC 24 ms
12,800 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 21 ms
11,008 KB
testcase_19 AC 40 ms
19,712 KB
testcase_20 AC 49 ms
23,680 KB
testcase_21 AC 40 ms
19,712 KB
testcase_22 AC 34 ms
17,024 KB
testcase_23 AC 28 ms
13,824 KB
testcase_24 AC 50 ms
23,296 KB
testcase_25 AC 28 ms
13,696 KB
testcase_26 AC 39 ms
19,072 KB
testcase_27 AC 49 ms
24,320 KB
testcase_28 AC 30 ms
15,232 KB
testcase_29 AC 32 ms
15,616 KB
testcase_30 AC 31 ms
15,488 KB
testcase_31 AC 50 ms
24,064 KB
testcase_32 AC 22 ms
11,392 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 57 ms
28,032 KB
testcase_35 AC 58 ms
28,032 KB
testcase_36 AC 58 ms
28,032 KB
testcase_37 AC 58 ms
28,160 KB
testcase_38 AC 58 ms
28,032 KB
testcase_39 AC 34 ms
21,504 KB
testcase_40 AC 27 ms
17,024 KB
testcase_41 AC 36 ms
22,528 KB
testcase_42 AC 26 ms
16,000 KB
testcase_43 AC 13 ms
8,448 KB
testcase_44 AC 32 ms
20,352 KB
testcase_45 AC 25 ms
15,872 KB
testcase_46 AC 8 ms
5,632 KB
testcase_47 AC 14 ms
9,216 KB
testcase_48 AC 30 ms
18,304 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 61 ms
28,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

const NUM_STATES: usize = 5;

fn main() {
    input! {
        n: usize,
        aa: [usize; n],
        bb: [usize; n],
        cc: [usize; n],
    }

    let mut dp1 = vec![[0_usize; NUM_STATES]; n + 1];
    for i in 0..n {
        let weights = [aa[i], bb[i], cc[i], bb[i], aa[i]];
        for state in 0..NUM_STATES {
            for next_state in state..NUM_STATES {
                dp1[i + 1][next_state] =
                    dp1[i + 1][next_state].max(dp1[i][state] + weights[next_state]);
            }
        }
    }

    let mut dp2 = vec![[0_usize; NUM_STATES]; n + 1];
    for i in 0..n {
        let weights = [aa[i], bb[i], aa[i], bb[i], aa[i]];
        for state in 0..NUM_STATES {
            for next_state in state..NUM_STATES {
                dp2[i + 1][next_state] =
                    dp2[i + 1][next_state].max(dp2[i][state] + weights[next_state]);
            }
        }
    }

    let ans = dp1[n][2..].iter().chain(&dp2[n][3..]).max().unwrap();
    println!("{}", ans);
}
0