結果

問題 No.2889 Rusk
ユーザー ra5anchorra5anchor
提出日時 2024-09-13 22:35:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 82,076 KB
実行使用メモリ 145,392 KB
最終ジャッジ日時 2024-09-13 22:36:06
合計ジャッジ時間 11,381 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,864 KB
testcase_01 AC 43 ms
52,480 KB
testcase_02 AC 38 ms
52,608 KB
testcase_03 AC 39 ms
52,736 KB
testcase_04 AC 39 ms
53,632 KB
testcase_05 AC 39 ms
52,864 KB
testcase_06 AC 40 ms
53,504 KB
testcase_07 AC 38 ms
52,828 KB
testcase_08 AC 39 ms
53,248 KB
testcase_09 AC 45 ms
54,016 KB
testcase_10 AC 39 ms
52,736 KB
testcase_11 AC 39 ms
52,992 KB
testcase_12 AC 40 ms
53,632 KB
testcase_13 AC 40 ms
53,376 KB
testcase_14 AC 90 ms
77,608 KB
testcase_15 AC 123 ms
89,004 KB
testcase_16 AC 200 ms
110,092 KB
testcase_17 AC 110 ms
84,276 KB
testcase_18 AC 165 ms
96,980 KB
testcase_19 AC 256 ms
125,600 KB
testcase_20 AC 271 ms
134,812 KB
testcase_21 AC 255 ms
124,836 KB
testcase_22 AC 216 ms
125,636 KB
testcase_23 AC 198 ms
112,844 KB
testcase_24 AC 299 ms
134,176 KB
testcase_25 AC 192 ms
112,968 KB
testcase_26 AC 239 ms
125,700 KB
testcase_27 AC 279 ms
136,720 KB
testcase_28 AC 208 ms
118,792 KB
testcase_29 AC 223 ms
122,764 KB
testcase_30 AC 211 ms
122,624 KB
testcase_31 AC 284 ms
136,216 KB
testcase_32 AC 174 ms
99,092 KB
testcase_33 AC 104 ms
81,536 KB
testcase_34 AC 304 ms
144,296 KB
testcase_35 AC 305 ms
141,436 KB
testcase_36 AC 307 ms
142,780 KB
testcase_37 AC 307 ms
141,168 KB
testcase_38 AC 326 ms
141,192 KB
testcase_39 AC 267 ms
138,460 KB
testcase_40 AC 247 ms
128,184 KB
testcase_41 AC 275 ms
145,392 KB
testcase_42 AC 238 ms
112,384 KB
testcase_43 AC 175 ms
96,384 KB
testcase_44 AC 276 ms
137,632 KB
testcase_45 AC 231 ms
112,384 KB
testcase_46 AC 133 ms
88,960 KB
testcase_47 AC 169 ms
98,404 KB
testcase_48 AC 255 ms
131,704 KB
testcase_49 AC 42 ms
53,120 KB
testcase_50 AC 39 ms
52,864 KB
testcase_51 AC 39 ms
52,864 KB
testcase_52 AC 39 ms
52,736 KB
testcase_53 AC 39 ms
52,736 KB
testcase_54 AC 276 ms
142,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

dp = [[-10**18]*5 for _ in range(N+1)]

for j in range(5):
    dp[0][j] = 0

for i in range(N):
    dp[i+1][0] = max(dp[i+1][0], dp[i][0] + A[i])
    dp[i+1][1] = max(dp[i+1][1], dp[i][0] + A[i])
    dp[i+1][2] = max(dp[i+1][2], dp[i][0] + A[i])
    dp[i+1][3] = max(dp[i+1][3], dp[i][0] + A[i])
    dp[i+1][4] = max(dp[i+1][4], dp[i][0] + A[i])
        
    dp[i+1][1] = max(dp[i+1][1], dp[i][1] + B[i])
    dp[i+1][2] = max(dp[i+1][2], dp[i][1] + B[i])
    dp[i+1][3] = max(dp[i+1][3], dp[i][1] + B[i])
    dp[i+1][4] = max(dp[i+1][4], dp[i][1] + B[i])

    dp[i+1][2] = max(dp[i+1][2], dp[i][2] + C[i])
    dp[i+1][3] = max(dp[i+1][3], dp[i][2] + C[i])
    dp[i+1][4] = max(dp[i+1][4], dp[i][2] + C[i])

    dp[i+1][3] = max(dp[i+1][3], dp[i][3] + B[i])
    dp[i+1][4] = max(dp[i+1][4], dp[i][3] + B[i])

    dp[i+1][4] = max(dp[i+1][4], dp[i][4] + A[i])

ans1 = max(dp[N])

dp_ = [[-10**18]*5 for _ in range(N+1)]

for j in range(5):
    dp_[0][j] = 0

for i in range(N):
    dp_[i+1][0] = max(dp_[i+1][0], dp_[i][0] + A[i])
    dp_[i+1][1] = max(dp_[i+1][1], dp_[i][0] + A[i])
    dp_[i+1][2] = max(dp_[i+1][2], dp_[i][0] + A[i])
    dp_[i+1][3] = max(dp_[i+1][3], dp_[i][0] + A[i])
    dp_[i+1][4] = max(dp_[i+1][4], dp_[i][0] + A[i])
        
    dp_[i+1][1] = max(dp_[i+1][1], dp_[i][1] + B[i])
    dp_[i+1][2] = max(dp_[i+1][2], dp_[i][1] + B[i])
    dp_[i+1][3] = max(dp_[i+1][3], dp_[i][1] + B[i])
    dp_[i+1][4] = max(dp_[i+1][4], dp_[i][1] + B[i])

    dp_[i+1][2] = max(dp_[i+1][2], dp_[i][2] + A[i])
    dp_[i+1][3] = max(dp_[i+1][3], dp_[i][2] + A[i])
    dp_[i+1][3] = max(dp_[i+1][4], dp_[i][2] + A[i])

    dp_[i+1][3] = max(dp_[i+1][3], dp_[i][3] + B[i])
    dp_[i+1][4] = max(dp_[i+1][4], dp_[i][3] + B[i])

    dp_[i+1][4] = max(dp_[i+1][4], dp_[i][4] + A[i])

ans2 = max(dp_[N])

print(max(ans1, ans2))
0