結果
問題 |
No.78 クジ付きアイスバー
|
ユーザー |
![]() |
提出日時 | 2022-07-06 03:31:14 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 619 bytes |
コンパイル時間 | 98 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-12-17 19:09:35 |
合計ジャッジ時間 | 5,017 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
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 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