結果
| 問題 |
No.2889 Rusk
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-09-14 14:28:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 698 ms / 2,000 ms |
| コード長 | 1,517 bytes |
| コンパイル時間 | 303 ms |
| コンパイル使用メモリ | 82,192 KB |
| 実行使用メモリ | 142,528 KB |
| 最終ジャッジ日時 | 2024-09-14 14:28:49 |
| 合計ジャッジ時間 | 21,317 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
from enum import IntEnum, auto
# ステート遷移
class E(IntEnum):
S = 0 # 開始
Nothing1 = auto()
Nothing2 = auto()
Nothing3 = auto()
Single1 = auto()
Single2 = auto()
Both = auto()
def nexts(self):
match self:
case E.S: return [E.Nothing1, E.Single1, E.Both]
case E.Nothing1: return [E.Nothing1, E.Single1, E.Both]
case E.Nothing2: return [E.Nothing2, E.Single2]
case E.Nothing3: return [E.Nothing3]
case E.Single1: return [E.Single1, E.Both, E.Nothing2]
case E.Single2: return [E.Single2, E.Nothing3]
case E.Both: return [E.Both, E.Single2, E.Nothing3]
assert False
def cost(self, a, b, c):
match self:
case E.S: return 0
case E.Nothing1 | E.Nothing2 | E.Nothing3: return a
case E.Single1 | E.Single2: return b
case E.Both: return c
assert False
@staticmethod
def states():
for fm in E:
for to in fm.nexts():
yield fm, to
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
dp = [[0] * len(E) for _ in range(N+1)]
for i, (a, b, c) in enumerate(zip(A, B, C)):
for fm, to in E.states():
dp[i+1][to] = max(dp[i+1][to], dp[i][fm] + to.cost(a, b, c))
end_states = [E.Single1, E.Single2, E.Both, E.Nothing3]
ans = max(dp[N][s] for s in end_states)
print(ans)
norioc