結果

問題 No.974 最後の日までに
ユーザー mkawa2mkawa2
提出日時 2020-01-19 01:59:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,905 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 135,948 KB
最終ジャッジ日時 2023-09-11 01:50:33
合計ジャッジ時間 59,300 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1,540 ms
134,996 KB
testcase_12 AC 1,525 ms
134,956 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,654 ms
134,672 KB
testcase_24 WA -
testcase_25 AC 18 ms
8,620 KB
testcase_26 AC 19 ms
8,588 KB
testcase_27 AC 1,118 ms
79,936 KB
testcase_28 AC 1,512 ms
109,728 KB
testcase_29 AC 16 ms
8,460 KB
testcase_30 AC 1,578 ms
115,124 KB
testcase_31 AC 17 ms
8,364 KB
testcase_32 AC 17 ms
8,484 KB
testcase_33 AC 961 ms
85,972 KB
testcase_34 AC 1,628 ms
134,680 KB
testcase_35 AC 17 ms
8,500 KB
testcase_36 AC 17 ms
8,472 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 17 ms
8,324 KB
testcase_40 WA -
testcase_41 AC 1,106 ms
87,192 KB
testcase_42 WA -
testcase_43 AC 1,624 ms
134,524 KB
testcase_44 WA -
testcase_45 AC 937 ms
86,324 KB
testcase_46 AC 17 ms
8,460 KB
testcase_47 AC 17 ms
8,380 KB
testcase_48 AC 16 ms
8,388 KB
testcase_49 AC 16 ms
8,552 KB
testcase_50 AC 17 ms
8,420 KB
testcase_51 AC 16 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def dfsl(i=0, like=0, money=0, last=False):
        if i >= n // 2:
            left.append((money, like, last))
            return
        # バイトの場合
        dfsl(i + 1, like, money + aa[i], last)
        # 学校の場合
        dfsl(i + 2, like + bb[i + 1], money - cc[i + 1], i == n // 2 - 1)

    def dfsr(i=-1, like=0, money=0, first=False):
        if i == -1: i = n // 2
        if i >= n:
            right.append((money, like, first))
            return
        # バイトの場合
        dfsr(i + 1, like, money + aa[i], first)
        # 学校の場合
        if i + 1 < n: dfsr(i + 2, like + bb[i + 1], money - cc[i + 1], i == n // 2)

    n = II()
    aa = []
    bb = []
    cc = []
    for _ in range(n):
        a, b, c = MI()
        aa += [a]
        bb += [b]
        cc += [c]
    # 学校に行く日を固定すると、次の日はデート、その他の日はバイトと一意に決まる
    # 期間を半分に分け、前後半ともに全列挙する
    left = []
    dfsl()
    right = []
    dfsr()
    # 他の結果と比べて、残金も少ないし好感度も低いものは不要なので削除する
    # 残金を降順にしたとき好感度は昇順になるはず
    # なっていない結果を削除
    left.sort(key=lambda x: (x[2], -x[0], -x[1]))
    # print(left)
    plike = -1
    plast = False
    nl = []
    for i, (money, like, last) in enumerate(left):
        if plast != last: plike = -1
        if like <= plike: continue
        nl.append((money, like, last))
        plike, plast = like, last
    # print(nl)

    right.sort(key=lambda x: (x[2], -x[0], -x[1]))
    # print(right)
    plike = -1
    pfirst = False
    nr = []
    for i, (money, like, first) in enumerate(right):
        if pfirst != first: plike = -1
        if like <= plike: continue
        nr.append((money, like, first))
        plike, pfirst = like, first
    # print(nr)
    # left,rightともに残金でソートし直してしゃくとり法
    # leftは左から、rightは右から、残金の合計が負にならないように動かす
    # ただし、last,firstがともにTrueのときは選べない
    nl.sort()
    nr.sort()
    # print(nl)
    # print(nr)
    j = len(nr) - 1
    ans = 0
    for i in range(len(nl)):
        lm, ll, last = nl[i]
        while 1:
            rm, rl, first = nr[j]
            if (not (last and first)) and lm + rm >= 0 and ll + rl > ans: ans = ll + rl
            if j == 0 or lm + nr[j - 1][0] < 0: break
            j -= 1
    print(ans)

main()
0