結果

問題 No.59 鉄道の旅
ユーザー gigurururugigurururu
提出日時 2015-04-24 23:35:27
言語 Ruby
(3.2.2)
結果
AC  
実行時間 310 ms / 5,000 ms
コード長 356 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 11,572 KB
実行使用メモリ 35,688 KB
最終ジャッジ日時 2023-08-26 05:38:58
合計ジャッジ時間 3,173 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
23,284 KB
testcase_01 AC 86 ms
23,012 KB
testcase_02 AC 86 ms
23,196 KB
testcase_03 AC 85 ms
23,092 KB
testcase_04 AC 243 ms
32,224 KB
testcase_05 AC 86 ms
23,240 KB
testcase_06 AC 87 ms
23,084 KB
testcase_07 AC 85 ms
23,280 KB
testcase_08 AC 110 ms
23,924 KB
testcase_09 AC 103 ms
23,448 KB
testcase_10 AC 107 ms
23,528 KB
testcase_11 AC 96 ms
23,596 KB
testcase_12 AC 149 ms
30,684 KB
testcase_13 AC 252 ms
33,324 KB
testcase_14 AC 310 ms
35,688 KB
testcase_15 AC 86 ms
23,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:4: warning: assigned but unused variable - l
Syntax OK

ソースコード

diff #

BIT=[0]*1000001
def add x,v;(BIT[x]+=v;x+=x&-x)while BIT[x];end
def sum x;s=0;(s+=BIT[x];x&=x-1)while x>0;s;end
l=[]
_,k,*t=$<.read.split.map &:to_i
cnt=Hash.new{0}
all=0
t.map{|w|
  if w>0
    if all-sum(w-1)<k
      cnt[w]+=1
      all+=1
      add(w,1)
    end
  else
    if cnt[-w]>0
      cnt[-w]-=1
      all-=1
      add(-w,-1)
    end
  end
}
p all
0