結果
問題 | No.2889 Rusk |
ユーザー | ra5anchor |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
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))