ログインしてください。
提出 #44529976
ソースコード 拡げる
class BIT
def initialize n
@a = [0]*(n+1) # 1-indexed internally
end
def [] i
i += 1
s = 0
while 0<i
s += @a[i]
i &= i-1
end
return s
end
def lb s
z = @a.size-1
i,t,b = 0,0,1<<z.bit_length
t += @a[i|=b] if i|b<=z && t+@a[i|b]<s while 0<b >>= 1
return i if i<z # i は1大きい内部インデックス(もしくは 0)だけど、求めた添字が s 未満の値を返す最大の添字であり、s の lower_bound としては +1 したものを返したいから、足し引きして内部インデックスそのままの値を返す(アクセス可能な範囲(0..z-1)なら)。
end
def add i,d
i += 1
while i<@a.size
@a[i] += d
i += i&-i
end
end
def inc i; add i,1 end
def dec i; add i,-1 end
end
(N,M,H),*AB = $<.map{|ln| ln.split.map(&:to_i) }
T = Array.new(M+1){[]}
AB.each{|a,b|
T[b]<<a
}
X = [0]
T.each{|as|
s = 0
as.each{|a|
X<<s += a
}
}
X.uniq!
X.sort!
X.reverse!
I = X.each_with_index.to_h
Ord = BIT.new I.size
Sum = BIT.new I.size
Ans = []
k = dmg = 0
T.map!{ 0 }
Ord.add I[0],M
AB.each_with_index{|(a,b),en|
t0 = T[b]
t1 = T[b] += a
Ord.dec I[t0]
Sum.add I[t0],-t0
Ord.inc I[t1]
Sum.add I[t1],t1
dmg += a
until M<k
i = Ord.lb k
ksum = Sum[i-1]+X[i]*(k-Ord[i-1])
break if dmg-ksum<H
Ans<<en
k += 1
end
}
Ans.concat [N]*(M+1-k)
puts Ans*' '
提出情報
| 提出日時 | |
|---|---|
| 問題 | G - Amulets |
| ユーザ | ds14050 |
| 言語 | Ruby (ruby 3.2.2) |
| 得点 | 575 |
| コード長 | 1412 Byte |
| 結果 | AC |
| 実行時間 | 1731 ms |
| メモリ | 91160 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 575 / 575 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 49 ms | 17184 KiB |
| 001.txt | AC | 50 ms | 17204 KiB |
| 002.txt | AC | 50 ms | 17232 KiB |
| 003.txt | AC | 831 ms | 59432 KiB |
| 004.txt | AC | 749 ms | 56660 KiB |
| 005.txt | AC | 809 ms | 55904 KiB |
| 006.txt | AC | 155 ms | 23496 KiB |
| 007.txt | AC | 407 ms | 37160 KiB |
| 008.txt | AC | 376 ms | 37160 KiB |
| 009.txt | AC | 1058 ms | 67704 KiB |
| 010.txt | AC | 1442 ms | 80896 KiB |
| 011.txt | AC | 1014 ms | 67696 KiB |
| 012.txt | AC | 1105 ms | 65528 KiB |
| 013.txt | AC | 1128 ms | 65344 KiB |
| 014.txt | AC | 1120 ms | 65816 KiB |
| 015.txt | AC | 1132 ms | 67604 KiB |
| 016.txt | AC | 1136 ms | 65644 KiB |
| 017.txt | AC | 1052 ms | 70044 KiB |
| 018.txt | AC | 1130 ms | 70800 KiB |
| 019.txt | AC | 1173 ms | 71764 KiB |
| 020.txt | AC | 1190 ms | 70844 KiB |
| 021.txt | AC | 1168 ms | 69320 KiB |
| 022.txt | AC | 1144 ms | 68428 KiB |
| 023.txt | AC | 1080 ms | 70664 KiB |
| 024.txt | AC | 1165 ms | 70952 KiB |
| 025.txt | AC | 1152 ms | 71076 KiB |
| 026.txt | AC | 1156 ms | 71132 KiB |
| 027.txt | AC | 1124 ms | 71088 KiB |
| 028.txt | AC | 1138 ms | 71072 KiB |
| 029.txt | AC | 1046 ms | 59936 KiB |
| 030.txt | AC | 1244 ms | 73704 KiB |
| 031.txt | AC | 1249 ms | 74060 KiB |
| 032.txt | AC | 1251 ms | 74632 KiB |
| 033.txt | AC | 1242 ms | 74728 KiB |
| 034.txt | AC | 1219 ms | 74068 KiB |
| 035.txt | AC | 896 ms | 52708 KiB |
| 036.txt | AC | 1331 ms | 63652 KiB |
| 037.txt | AC | 1429 ms | 73668 KiB |
| 038.txt | AC | 1469 ms | 73852 KiB |
| 039.txt | AC | 1459 ms | 74736 KiB |
| 040.txt | AC | 1506 ms | 74824 KiB |
| 041.txt | AC | 874 ms | 52820 KiB |
| 042.txt | AC | 1279 ms | 58828 KiB |
| 043.txt | AC | 1665 ms | 73804 KiB |
| 044.txt | AC | 1686 ms | 82532 KiB |
| 045.txt | AC | 1677 ms | 84156 KiB |
| 046.txt | AC | 1697 ms | 84176 KiB |
| 047.txt | AC | 890 ms | 58836 KiB |
| 048.txt | AC | 1176 ms | 70332 KiB |
| 049.txt | AC | 1571 ms | 82832 KiB |
| 050.txt | AC | 1731 ms | 89260 KiB |
| 051.txt | AC | 1729 ms | 89264 KiB |
| 052.txt | AC | 1707 ms | 91160 KiB |
| example0.txt | AC | 52 ms | 17140 KiB |
| example1.txt | AC | 49 ms | 17512 KiB |