結果
問題 | No.974 最後の日までに |
ユーザー | tcltk |
提出日時 | 2021-07-03 06:30:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,531 ms / 2,000 ms |
コード長 | 4,391 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 224,448 KB |
最終ジャッジ日時 | 2024-06-30 00:35:30 |
合計ジャッジ時間 | 36,851 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 966 ms
224,072 KB |
testcase_01 | AC | 1,429 ms
224,208 KB |
testcase_02 | AC | 1,405 ms
224,060 KB |
testcase_03 | AC | 1,432 ms
224,204 KB |
testcase_04 | AC | 1,422 ms
224,200 KB |
testcase_05 | AC | 1,416 ms
224,192 KB |
testcase_06 | AC | 1,479 ms
224,076 KB |
testcase_07 | AC | 1,440 ms
223,952 KB |
testcase_08 | AC | 1,402 ms
224,328 KB |
testcase_09 | AC | 1,398 ms
224,072 KB |
testcase_10 | AC | 1,399 ms
224,200 KB |
testcase_11 | AC | 1,408 ms
224,448 KB |
testcase_12 | AC | 1,385 ms
224,204 KB |
testcase_13 | AC | 1,430 ms
224,332 KB |
testcase_14 | AC | 1,398 ms
224,200 KB |
testcase_15 | AC | 1,382 ms
223,944 KB |
testcase_16 | AC | 1,378 ms
224,072 KB |
testcase_17 | AC | 164 ms
89,600 KB |
testcase_18 | AC | 170 ms
89,600 KB |
testcase_19 | AC | 163 ms
89,472 KB |
testcase_20 | AC | 165 ms
89,472 KB |
testcase_21 | AC | 166 ms
89,472 KB |
testcase_22 | AC | 164 ms
89,600 KB |
testcase_23 | AC | 164 ms
89,728 KB |
testcase_24 | AC | 168 ms
89,472 KB |
testcase_25 | AC | 153 ms
88,704 KB |
testcase_26 | AC | 157 ms
88,832 KB |
testcase_27 | AC | 1,387 ms
209,056 KB |
testcase_28 | AC | 1,509 ms
224,076 KB |
testcase_29 | AC | 138 ms
86,912 KB |
testcase_30 | AC | 184 ms
89,600 KB |
testcase_31 | AC | 137 ms
86,912 KB |
testcase_32 | AC | 137 ms
86,784 KB |
testcase_33 | AC | 956 ms
168,880 KB |
testcase_34 | AC | 1,531 ms
224,332 KB |
testcase_35 | AC | 138 ms
86,784 KB |
testcase_36 | AC | 136 ms
86,528 KB |
testcase_37 | AC | 215 ms
91,392 KB |
testcase_38 | AC | 134 ms
86,912 KB |
testcase_39 | AC | 135 ms
86,400 KB |
testcase_40 | AC | 151 ms
88,832 KB |
testcase_41 | AC | 155 ms
89,600 KB |
testcase_42 | AC | 231 ms
93,184 KB |
testcase_43 | AC | 236 ms
93,312 KB |
testcase_44 | AC | 228 ms
92,672 KB |
testcase_45 | AC | 236 ms
93,056 KB |
testcase_46 | AC | 136 ms
86,784 KB |
testcase_47 | AC | 136 ms
86,784 KB |
testcase_48 | AC | 135 ms
86,784 KB |
testcase_49 | AC | 136 ms
86,528 KB |
testcase_50 | AC | 138 ms
86,528 KB |
testcase_51 | AC | 137 ms
86,912 KB |
ソースコード
#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """52 # 3316937975 948971987273 245356275212 # 7622812803 165560224258 237733462410 # 5049794700 725262318970 236000605685 # 4601698392 10569666447 239021720096 # 976650 203973357560 244070538145 # 6750896419 743731276134 241921340119 # 6672133707 96027496166 235250183063 # 6141923153 188257360777 235859156328 # 2377616496 835017164869 240153673539 # 3697283028 188448574493 242598313666 # 6997091419 57289443968 237978838743 # 5481244831 858935768046 236194876939 # 7582706228 266693610721 235609262128 # 806840622 645244514026 240283666340 # 7225545701 905847830553 240640826864 # 8312979195 764407581858 233134688292 # 8939241886 968933490364 231420992109 # 3661208074 515347058892 236072763228 # 2031892049 66512164290 242980113066 # 6095986014 699428791235 240545335127 # 3940372534 193748065544 238636854641 # 5603786625 113723605765 239129054028 # 7493777737 620274173901 235575648828 # 9619303168 95205614004 231560132285 # 6445461447 420813714741 232608448575 # 3436603117 448753477910 238791148624 # 5349268149 561710581962 239887341920 # 3883766620 75266996501 239440178421 # 1445171801 13320184566 243344274768 # 1419672038 108596353216 245808369350 # 970068159 526852966793 246283472991 # 2640836137 204086515400 245062308892 # 2788233781 307455107129 243244143269 # 7177164357 79179860484 238707815051 # 9084820943 665454039325 232411227890 # 4340686688 304039018989 235247705556 # 3257845220 388040361266 241074681282 # 648273444 718491850531 244767094525 # 6844189839 141803564246 241180749907 # 9575488316 894353898470 232253535034 # 7509360687 783182841936 231588364187 # 4313440218 732960840861 236850412283 # 6036068327 650944036934 238323704644 # 564458036 49332764755 242072686825 # 7743489054 986082188868 240365266098 # 857041410 222310922549 240072682725 # 173403905 161280832828 247642767872 # 4233911554 520867603733 244265897729 # 7715877116 736893921793 236723424520 # 8289333109 560874966506 232668002963 # 1720010053 446542113739 238663870025 # 185220255 277985184334 246767982882 # """ # sys.stdin = io.StringIO(_INPUT) W = int(input()) A, B, C = [], [], [] for _ in range(W): a, b, c = map(int, input().split()) A.append(a) B.append(b) C.append(c) A.append(0) B.append(0) C.append(0) N1 = W//2 N2 = W-N1 dp1 = [collections.defaultdict(int) for _ in range(N1+2)] dp1[0][0] = 0 for day in range(N1): for money, love in dp1[day].items(): # 学校 -> デート dp1[day+2][money-C[day+1]] = max(dp1[day+2][money-C[day+1]], love+B[day+1]) # アルバイト dp1[day+1][money+A[day]] = max(dp1[day+1][money+A[day]], love) dp2a = [collections.defaultdict(int) for _ in range(N2+2)] dp2a[0][0] = 0 for day in range(N2): for money, love in dp2a[day].items(): # 学校 -> デート dp2a[day+2][money-C[N1+day+1]] = max(dp2a[day+2][money-C[N1+day+1]], love+B[N1+day+1]) # アルバイト dp2a[day+1][money+A[N1+day]] = max(dp2a[day+1][money+A[N1+day]], love) dp2b = [collections.defaultdict(int) for _ in range(N2+1)] dp2b[0][0] = 0 for day in range(N2-1): for money, love in dp2b[day].items(): # 学校 -> デート dp2b[day+2][money-C[N1+1+day+1]] = max(dp2b[day+2][money-C[N1+1+day+1]], love+B[N1+1+day+1]) # アルバイト dp2b[day+1][money+A[N1+1+day]] = max(dp2b[day+1][money+A[N1+1+day]], love) max_love = 0 result2a = list(sorted(dp2a[N2].items())) max_love2a = [0] * (len(result2a)+1) for i in reversed(range(len(result2a))): max_love2a[i] = max(max_love2a[i+1], result2a[i][1]) for money1, love1 in dp1[N1].items(): k = bisect.bisect_left(result2a, (-money1, 0)) if k < len(result2a): love2 = max_love2a[k] max_love = max(max_love, love1+love2) result2b = list(sorted(dp2b[N2-1].items())) max_love2b = [0] * (len(result2b)+1) for i in reversed(range(len(result2b))): max_love2b[i] = max(max_love2b[i+1], result2b[i][1]) for money1, love1 in dp1[N1+1].items(): k = bisect.bisect_left(result2b, (-money1, 0)) if k < len(result2b): love2 = max_love2b[k] max_love = max(max_love, love1+love2) print(max_love)