結果

問題 No.78 クジ付きアイスバー
ユーザー simansiman
提出日時 2016-03-23 23:44:59
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-10-06 19:03:43
合計ジャッジ時間 4,512 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Yukicoder
  def initialize
    n, k = gets.chomp.split.map(&:to_i)
    s = gets.chomp

    list = Array.new(n, 0)
    buy_count = 0
    atari_cost = 0

    s.chars.each_with_index do |ch, index|
      if atari_cost > 0
        atari_cost -= 1
      else
        buy_count += 1
      end

      list[index] = buy_count

      if ch == '1'
        atari_cost += 1
      elsif ch == '2'
        atari_cost += 2
      end
    end

    if n >= k
      puts list[k-1]
    else
      x = k / n
      y = [buy_count, atari_cost].map{|i| i * x}

      if k % n == 0
        puts [y[0] - y[1], 1].max
      else
        puts [list[k%n-1] + y[0] - y[1], buy_count].max
      end
    end

  end
end

Yukicoder.new
0