結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-07-06 03:32:40 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 5,000 ms |
| コード長 | 639 bytes |
| コンパイル時間 | 395 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-12-17 19:10:32 |
| 合計ジャッジ時間 | 5,208 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
コンパイルメッセージ
Syntax OK
ソースコード
N, K = gets.split.map(&:to_i)
S = gets.chomp.chars.map(&:to_i)
remain = 0
ans = 0
k = K
visited = Hash.new
buy_hist = []
i = 0
loop do
cur_remain = remain
buy_cnt = 0
if visited[cur_remain]
s, _ = visited[cur_remain]
d = k / N
arr = buy_hist[s..]
ans += d * arr.sum
k %= N
break if k <= 0
end
S.each do |s|
if remain <= 0
buy_cnt += 1
else
remain -= 1
end
k -= 1
remain += s
break if k <= 0
end
visited[cur_remain] = [i, buy_cnt]
buy_hist << buy_cnt
ans += buy_cnt
i += 1
break if buy_cnt == 0 && cur_remain < remain
break if k <= 0
end
puts ans
siman