結果

問題 No.974 最後の日までに
ユーザー mkawa2mkawa2
提出日時 2020-01-19 02:27:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,995 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 11,144 KB
実行使用メモリ 136,084 KB
最終ジャッジ日時 2023-09-11 02:46:35
合計ジャッジ時間 58,583 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,496 ms
134,792 KB
testcase_02 AC 1,465 ms
134,888 KB
testcase_03 AC 1,486 ms
134,028 KB
testcase_04 AC 1,471 ms
134,124 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1,483 ms
135,856 KB
testcase_10 AC 1,504 ms
135,864 KB
testcase_11 AC 1,551 ms
135,092 KB
testcase_12 AC 1,514 ms
135,176 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,555 ms
135,276 KB
testcase_16 AC 1,561 ms
135,124 KB
testcase_17 AC 1,611 ms
135,108 KB
testcase_18 AC 1,631 ms
135,168 KB
testcase_19 AC 1,620 ms
134,512 KB
testcase_20 AC 1,595 ms
135,208 KB
testcase_21 AC 1,618 ms
135,056 KB
testcase_22 AC 1,657 ms
134,652 KB
testcase_23 AC 1,636 ms
134,636 KB
testcase_24 AC 1,681 ms
134,696 KB
testcase_25 AC 18 ms
8,552 KB
testcase_26 AC 18 ms
8,676 KB
testcase_27 AC 1,115 ms
80,036 KB
testcase_28 AC 1,503 ms
109,896 KB
testcase_29 AC 17 ms
8,492 KB
testcase_30 AC 1,558 ms
114,944 KB
testcase_31 AC 17 ms
8,424 KB
testcase_32 AC 17 ms
8,392 KB
testcase_33 AC 928 ms
86,168 KB
testcase_34 AC 1,591 ms
134,760 KB
testcase_35 AC 17 ms
8,388 KB
testcase_36 AC 17 ms
8,392 KB
testcase_37 WA -
testcase_38 AC 17 ms
8,368 KB
testcase_39 AC 17 ms
8,264 KB
testcase_40 AC 818 ms
63,292 KB
testcase_41 AC 1,100 ms
87,040 KB
testcase_42 AC 1,627 ms
134,532 KB
testcase_43 AC 1,612 ms
134,516 KB
testcase_44 AC 1,198 ms
97,516 KB
testcase_45 AC 929 ms
86,352 KB
testcase_46 AC 17 ms
8,436 KB
testcase_47 AC 17 ms
8,520 KB
testcase_48 AC 17 ms
8,392 KB
testcase_49 AC 17 ms
8,524 KB
testcase_50 AC 17 ms
8,492 KB
testcase_51 AC 17 ms
8,388 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:
            if last:money-=aa[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
                #print(ans,ll,rl,lm,rm)
            if j == 0 or lm + nr[j - 1][0] < 0: break
            j -= 1
    print(ans)

main()
0