結果

問題 No.974 最後の日までに
ユーザー mkawa2mkawa2
提出日時 2020-01-19 02:25:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,994 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 11,168 KB
実行使用メモリ 136,140 KB
最終ジャッジ日時 2023-09-11 02:41:15
合計ジャッジ時間 59,334 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1,602 ms
135,088 KB
testcase_18 AC 1,613 ms
135,148 KB
testcase_19 AC 1,625 ms
134,532 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 17 ms
8,384 KB
testcase_30 WA -
testcase_31 AC 17 ms
8,192 KB
testcase_32 AC 17 ms
8,476 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 17 ms
8,300 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

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