結果

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

ソースコード

diff #

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

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

    count -=1
    count += S[i].to_i
    if i>=k
        puts total
        exit
    end
    
}
#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
    if i>=k
        puts total
        exit
    end
    
}
puts total


0