結果
問題 | No.59 鉄道の旅 |
ユーザー | titia |
提出日時 | 2021-12-17 04:49:07 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 509 ms / 5,000 ms |
コード長 | 875 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 10,724 KB |
実行使用メモリ | 19,752 KB |
最終ジャッジ日時 | 2023-10-12 05:28:32 |
合計ジャッジ時間 | 3,631 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
15,660 KB |
testcase_01 | AC | 32 ms
15,652 KB |
testcase_02 | AC | 32 ms
15,688 KB |
testcase_03 | AC | 32 ms
15,688 KB |
testcase_04 | AC | 473 ms
19,400 KB |
testcase_05 | AC | 33 ms
15,604 KB |
testcase_06 | AC | 34 ms
15,672 KB |
testcase_07 | AC | 32 ms
15,604 KB |
testcase_08 | AC | 79 ms
16,276 KB |
testcase_09 | AC | 81 ms
16,136 KB |
testcase_10 | AC | 81 ms
16,420 KB |
testcase_11 | AC | 55 ms
16,036 KB |
testcase_12 | AC | 225 ms
16,904 KB |
testcase_13 | AC | 509 ms
19,752 KB |
testcase_14 | AC | 484 ms
19,664 KB |
testcase_15 | AC | 32 ms
15,736 KB |
ソースコード
N,K=map(int,input().split()) W=[int(input()) for i in range(N)] LEN=10**6+10 BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。 def update(v,w): # index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v): # [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ return ANS S=0 for w in W: if w>0: x=getvalue(w-1) if S-x>=K: True else: S+=1 update(w,1) else: w=-w if getvalue(w)>getvalue(w-1): update(w,-1) S-=1 print(S)