結果
問題 | No.2982 Logic Battle |
ユーザー |
![]() |
提出日時 | 2024-12-07 03:46:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 780 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 82,276 KB |
実行使用メモリ | 78,160 KB |
最終ジャッジ日時 | 2024-12-07 03:47:03 |
合計ジャッジ時間 | 5,033 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 38 |
ソースコード
from heapq import heappush, heappop N = int(input()) cards = [] for _ in range(N): A, B, C = map(int, input().split()) cards.append((A, B, C)) dp = [(-1, 0, 0)] for i in range(N): pp = [] dp, pp = pp, dp ds = [{}, {}, {}] for prev_j, x, tot in pp: for j in range(3): if prev_j == j: continue nx = x + cards[i][j] ntot = tot + nx # dp.append((j, max(0, nx-1), ntot)) d = ds[j] d[nx] = max(d.get(nx, -1), ntot) for j in range(3): d = ds[j] v = -1 for nx, ntot in sorted(d.items(), reverse=True): if v >= ntot: continue v = ntot dp.append((j, max(0, nx-1), ntot)) ans = max(tot for _, _, tot in dp) print(ans)