結果

問題 No.2889 Rusk
ユーザー norioc
提出日時 2024-09-14 02:04:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 1,546 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 142,464 KB
最終ジャッジ日時 2024-09-14 02:05:11
合計ジャッジ時間 21,787 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

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, E.Nothing3]
            case E.Nothing1: return [E.Nothing1, E.Single1, E.Both, E.Nothing3]
            case E.Nothing2: return [E.Nothing2, E.Single2]
            case E.Nothing3: return [E.Nothing3]
            case E.Single1: return [E.Single1, E.Both, E.Nothing2, E.Nothing3]
            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 in range(N):
    a, b, c = A[i], B[i], C[i]
    for fm, to in E.states():
        dp[i+1][to] = max(dp[i+1][to], dp[i][fm] + to.cost(a, b, c))

ends = [E.Single1, E.Single2, E.Both, E.Nothing3]
ans = max(dp[N][s] for s in ends)
print(ans)
0