結果

問題 No.618 labo-index
ユーザー RyutoRyuto
提出日時 2018-03-05 20:03:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,663 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 208,928 KB
最終ジャッジ日時 2023-10-11 15:25:09
合計ジャッジ時間 19,220 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,472 KB
testcase_01 AC 91 ms
71,232 KB
testcase_02 AC 91 ms
71,456 KB
testcase_03 AC 93 ms
71,436 KB
testcase_04 AC 202 ms
78,052 KB
testcase_05 AC 192 ms
78,744 KB
testcase_06 AC 98 ms
71,488 KB
testcase_07 AC 118 ms
76,644 KB
testcase_08 AC 146 ms
78,556 KB
testcase_09 AC 158 ms
78,240 KB
testcase_10 AC 179 ms
78,260 KB
testcase_11 AC 164 ms
78,272 KB
testcase_12 AC 150 ms
78,132 KB
testcase_13 AC 174 ms
78,508 KB
testcase_14 AC 151 ms
78,276 KB
testcase_15 AC 174 ms
78,692 KB
testcase_16 AC 186 ms
78,476 KB
testcase_17 AC 161 ms
78,240 KB
testcase_18 AC 212 ms
79,264 KB
testcase_19 AC 5,187 ms
208,928 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:
                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:
                    dp[k] = max(0, dp[k] - 1)
    elif event[0] == 3:
        x = event[1]
        addlist = [v+x for v in addlist]
        keylist = [i+x for i in keylist]
        dp_new = {k:dp[k-x] for k in keylist}
        dp = copy.deepcopy(dp_new)

    for i, k in enumerate(keylist[:-2]):
        if dp[k] == dp[keylist[i+1]]:
            del dp[k]
            del keylist[i]

    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