結果

問題 No.618 labo-index
ユーザー RyutoRyuto
提出日時 2018-03-05 20:48:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,856 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 210,764 KB
最終ジャッジ日時 2023-10-11 16:29:33
合計ジャッジ時間 17,967 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
75,772 KB
testcase_01 AC 87 ms
71,456 KB
testcase_02 AC 89 ms
71,364 KB
testcase_03 AC 88 ms
71,716 KB
testcase_04 AC 185 ms
78,404 KB
testcase_05 AC 198 ms
79,364 KB
testcase_06 AC 93 ms
71,492 KB
testcase_07 AC 112 ms
76,548 KB
testcase_08 AC 130 ms
77,616 KB
testcase_09 AC 155 ms
78,520 KB
testcase_10 AC 168 ms
79,024 KB
testcase_11 AC 141 ms
78,248 KB
testcase_12 AC 140 ms
78,308 KB
testcase_13 AC 160 ms
78,628 KB
testcase_14 AC 141 ms
78,180 KB
testcase_15 AC 168 ms
78,160 KB
testcase_16 AC 183 ms
78,496 KB
testcase_17 AC 140 ms
78,040 KB
testcase_18 AC 201 ms
79,316 KB
testcase_19 AC 5,038 ms
210,764 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python

import copy

Q = int(input())
events = []
for i in range(Q):
    events.append([int(x) for x in input().split()])

N = 0
addlist = [0]
keylist = []
dp = {}
for event in events:
    if event[0] == 1:
        x = event[1]
        N += 1
        addlist.append(x)
        keylist = sorted(list(set(keylist + [x])))
        for k in keylist:
            if k >= x:
                break
            else:
                dp[k] += 1
        if x in dp.keys():
            dp[x] += 1
        elif x == keylist[-1]:
            dp[x] = 1
        else:
            dp[x] = dp[keylist[keylist.index(x)+1]] + 1
    elif event[0] == 2:
        N -= 1
        if N == 0:
            dp = {}
            keylist = []
        else:
            x = addlist[event[1]]
            for k in keylist:
                if k > x:
                    break
                else:
                    dp[k] = max(0, dp[k] - 1)
            i = 0
            while i < len(keylist)-1:
                if dp[keylist[i]] == dp[keylist[i+1]]:
                    del dp[keylist[i]]
                    del keylist[i]
                else:
                    i += 1
    elif event[0] == 3:
        x = event[1]
        addlist = [v+x for v in addlist]
        keylist = [k+x for k in keylist]
        dp_new = {k:dp[k-x] for k in keylist}
        dp = copy.deepcopy(dp_new)

    ansdp = [(k, v) for k, v in dp.items() if k >= 0]
    if len(ansdp) == 0:
        print(0)
    else:
        ansdp.sort(reverse=True)
        for i, val in enumerate(ansdp):
            if val[1] >= val[0]:
                print(val[0])
                break
            elif i+1 == len(ansdp):
                print(val[1])
                break
            elif val[1] >= ansdp[i+1][0]:
                print(val[1])
                break
            else:
                continue
0