結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
norioc
|
| 提出日時 | 2024-07-15 10:10:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 71 ms / 5,000 ms |
| コード長 | 677 bytes |
| コンパイル時間 | 307 ms |
| コンパイル使用メモリ | 82,440 KB |
| 実行使用メモリ | 68,844 KB |
| 最終ジャッジ日時 | 2024-07-15 10:10:55 |
| 合計ジャッジ時間 | 4,016 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
from enum import IntEnum, auto
# ステート遷移
class E(IntEnum):
EAT = 0
NOT_EAT = auto()
def nexts(self):
match self:
case E.EAT: return [E.NOT_EAT]
case E.NOT_EAT: return [E.EAT, E.NOT_EAT]
assert False
def cost(self, x: int) -> int:
match self:
case E.EAT: return x
case E.NOT_EAT: return 0
assert False
N = int(input())
V = list(map(int, input().split()))
dp = [[0] * len(E) for _ in range(N+1)]
for i, v in enumerate(V):
for fm in E:
for to in fm.nexts():
dp[i+1][to] = max(dp[i+1][to], dp[i][fm] + to.cost(v))
ans = max(dp[N])
print(ans)
norioc