結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-04-01 01:08:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,165 bytes |
| コンパイル時間 | 343 ms |
| コンパイル使用メモリ | 82,428 KB |
| 実行使用メモリ | 159,520 KB |
| 最終ジャッジ日時 | 2024-06-25 15:43:12 |
| 合計ジャッジ時間 | 87,024 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 TLE * 30 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
W = int(readline())
m = map(int, read().split())
ABC = tuple(zip(m, m, m))
def gen_all_patterns(L, R):
"""L 日目約束なしの状態から、R日目約束なしの状態へ"""
n = R - L
dp = [[] 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 Q
def 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:
return
yield P[-1][1] + qy
answer = 0
for n in range(W // 2, W // 2 + 2):
x = max(solve(n))
if answer < x:
answer = x
print(answer)
maspy