結果

問題 No.78 クジ付きアイスバー
ユーザー simansiman
提出日時 2016-03-24 00:07:20
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 906 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-16 06:06:15
合計ジャッジ時間 4,850 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
12,032 KB
testcase_01 AC 94 ms
11,904 KB
testcase_02 AC 90 ms
12,160 KB
testcase_03 AC 89 ms
12,032 KB
testcase_04 AC 91 ms
12,160 KB
testcase_05 AC 93 ms
12,160 KB
testcase_06 AC 93 ms
12,032 KB
testcase_07 AC 91 ms
12,032 KB
testcase_08 AC 93 ms
12,160 KB
testcase_09 AC 91 ms
12,160 KB
testcase_10 AC 93 ms
12,160 KB
testcase_11 AC 90 ms
12,032 KB
testcase_12 AC 89 ms
12,032 KB
testcase_13 AC 90 ms
12,032 KB
testcase_14 AC 91 ms
11,904 KB
testcase_15 AC 90 ms
12,032 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 90 ms
12,032 KB
testcase_21 AC 90 ms
12,032 KB
testcase_22 AC 92 ms
12,160 KB
testcase_23 AC 91 ms
12,032 KB
testcase_24 AC 91 ms
12,032 KB
testcase_25 AC 89 ms
12,032 KB
testcase_26 AC 93 ms
12,032 KB
testcase_27 AC 92 ms
12,032 KB
testcase_28 AC 92 ms
12,032 KB
testcase_29 AC 90 ms
12,032 KB
testcase_30 AC 91 ms
12,032 KB
testcase_31 AC 93 ms
11,904 KB
testcase_32 AC 95 ms
12,032 KB
testcase_33 AC 93 ms
12,032 KB
testcase_34 AC 93 ms
12,160 KB
testcase_35 AC 90 ms
12,160 KB
testcase_36 AC 90 ms
12,032 KB
testcase_37 AC 89 ms
11,904 KB
testcase_38 AC 90 ms
12,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 - 1

      if k % n == 0
        y = [buy_count, atari_cost].map{|i| i * (x+1)}
        if y[1] > 0
          puts [y[0] - y[1] + 1, 1].max
        else
          puts [y[0] - y[1], 1].max
        end
      else
        y = [buy_count, atari_cost].map{|i| i * x}
        puts [buy_count + x * (buy_count - atari_cost) + [list[k%n-1] - atari_cost, 0].max, buy_count].max
      end
    end

  end
end

Yukicoder.new
0