結果

問題 No.78 クジ付きアイスバー
ユーザー simansiman
提出日時 2020-12-07 16:34:12
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 532 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 16,108 KB
最終ジャッジ日時 2023-10-17 16:31:59
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
16,108 KB
testcase_01 AC 78 ms
16,108 KB
testcase_02 AC 80 ms
16,108 KB
testcase_03 AC 75 ms
16,108 KB
testcase_04 AC 73 ms
16,108 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 73 ms
16,108 KB
testcase_15 AC 76 ms
16,108 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 76 ms
16,108 KB
testcase_21 AC 74 ms
16,108 KB
testcase_22 WA -
testcase_23 AC 76 ms
16,108 KB
testcase_24 AC 78 ms
16,108 KB
testcase_25 AC 78 ms
16,108 KB
testcase_26 WA -
testcase_27 AC 75 ms
16,108 KB
testcase_28 AC 73 ms
16,108 KB
testcase_29 AC 75 ms
16,108 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 74 ms
16,108 KB
testcase_33 AC 75 ms
16,108 KB
testcase_34 WA -
testcase_35 AC 76 ms
16,108 KB
testcase_36 AC 77 ms
16,108 KB
testcase_37 AC 74 ms
16,108 KB
testcase_38 AC 73 ms
16,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:4: warning: assigned but unused variable - min
Main.rb:5: warning: assigned but unused variable - max
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
S = gets.chomp

min = Float::INFINITY
max = -Float::INFINITY

cnt = 0

S.each_char do |s|
  cnt -= 1

  case s
  when '1'
    cnt += 1
  when '2'
    cnt += 2
  end
end

def f(x, cnt)
  x += cnt * (K / N)
  r = K % N

  r.times do |i|
    s = S[i]
    x -= 1
    return false if x < 0

    case s
    when '1'
      x += 1
    when '2'
      x += 2
    end
  end

  x >= 0
end

ng = 0
ok = K

while (ok - ng).abs >= 2
  x = (ok + ng) / 2

  if f(x, cnt)
    ok = x
  else
    ng = x
  end
end

puts ok
0