結果
問題 | No.974 最後の日までに |
ユーザー |
![]() |
提出日時 | 2020-04-01 01:08:43 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,165 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 159,260 KB |
最終ジャッジ日時 | 2024-06-25 15:46:42 |
合計ジャッジ時間 | 80,793 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 TLE * 30 |
ソースコード
#!/usr/bin/ python3.8import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesW = int(readline())m = map(int, read().split())ABC = tuple(zip(m, m, m))def gen_all_patterns(L, R):"""L 日目約束なしの状態から、R日目約束なしの状態へ"""n = R - Ldp = [[] for _ in range(n + 1)]dp[0] = [(0, 0)]for i, (a, b, c) in enumerate(ABC[L:R]):dp[i + 1] += [(x + a, y) for x, y in dp[i]]if i:dp[i + 1] += [(x - c, y + b) for x, y in dp[i - 1]]P = dp[-1]P.sort()Q = []for x, y in P:while Q and Q[-1][0] <= x and Q[-1][1] <= y:Q.pop()Q.append((x, y))return Qdef solve(n):""" n日目約束なしを経由するパターンを解く """P = gen_all_patterns(0, n)[::-1]Q = gen_all_patterns(n, W)[::-1]for qx, qy in Q:while P and P[-1][0] + qx < 0:P.pop()if not P:returnyield P[-1][1] + qyanswer = 0for n in range(W // 2, W // 2 + 2):x = max(solve(n))if answer < x:answer = xprint(answer)