結果

問題 No.59 鉄道の旅
ユーザー roiti46roiti46
提出日時 2015-02-24 16:23:11
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 385 ms / 5,000 ms
コード長 507 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 77,512 KB
実行使用メモリ 88,780 KB
最終ジャッジ日時 2023-08-26 05:37:02
合計ジャッジ時間 3,393 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
85,772 KB
testcase_01 AC 79 ms
85,744 KB
testcase_02 AC 82 ms
85,448 KB
testcase_03 AC 84 ms
86,648 KB
testcase_04 AC 258 ms
88,524 KB
testcase_05 AC 86 ms
86,508 KB
testcase_06 AC 86 ms
86,824 KB
testcase_07 AC 84 ms
86,724 KB
testcase_08 AC 131 ms
87,888 KB
testcase_09 AC 129 ms
88,456 KB
testcase_10 AC 138 ms
88,780 KB
testcase_11 AC 124 ms
87,828 KB
testcase_12 AC 385 ms
88,556 KB
testcase_13 AC 213 ms
88,620 KB
testcase_14 AC 272 ms
88,544 KB
testcase_15 AC 78 ms
84,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N,K = map(int,raw_input().split())
W = [int(raw_input()) for i in xrange(N)]
mw = 1000001
have = [0]*mw
D = int(math.ceil(mw**0.5))
bucket = [0]*(mw/D+1)
for i in xrange(N):
    p = abs(W[i])/D
    if W[i] > 0:
        cnt = 0
        for j in xrange(p,mw/D+1): cnt += bucket[j]
        for j in xrange(p*D,W[i]): cnt -= have[j]
        if cnt < K:
            have[W[i]] += 1
            bucket[p] += 1
    elif have[-W[i]] > 0:
        have[-W[i]] -= 1
        bucket[p] -= 1
print sum(bucket)
0