結果

問題 No.78 クジ付きアイスバー
ユーザー Tsuneo Yoshioka
提出日時 2014-11-26 01:51:51
言語 Ruby
(3.4.1)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-08 00:00:20
合計ジャッジ時間 4,755 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

total = 1
count = 1
(0...N).each{|i|
    if i>=k
        puts total
        exit
    end
    if count == 0
        count +=1
        total +=1
        #puts "i=#{i}, count=#{count}, total=#{total}"
    end

    count -=1
    count += S[i].to_i
    
}
#puts "1:total=#{total}, count=#{count}, k=#{k}, N=#{N}"
k -= N
su = S.split('').map(&:to_i).inject(&:+)
#puts "su=#{su}"
if su > S.length
    count += (k/N) * (su - S.length )
else
    total += (k/N) * (S.length - su)
end
    k%=N
#uts "2:total=#{total}, count=#{count}, k=#{k}, N=#{N}"

(0...k).each{|i|
    if count == 0
        count +=1
        total +=1
        #puts "i=#{i}, total=#{total}"
    end
    count -=1
    count += S[i].to_i

    
}
puts total


0