結果

問題 No.1935 Water Simulation
ユーザー magurofly
提出日時 2022-05-13 21:37:18
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 512 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-07-22 01:10:23
合計ジャッジ時間 4,611 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a, b, c, d, n = gets.split.map(&:to_i)
as = [a, b, c, d]
xs = [a, 0, 0, 0]

hash = {}
hash[xs] = 0
len = 1
n.times do |i|
    i %= 4
    j = (i + 1) % 4
    h = [xs[i], as[j] - xs[j]].min
    xs[i] -= h
    xs[j] += h
    break if hash[xs]
    hash[xs] = len
    len += 1
end

tail = hash[xs]
cycle = len - tail

m = (n <= tail) ? n : tail + (n - tail) % cycle
xs = [a, 0, 0, 0]
m.times do |i|
    i %= 4
    j = (i + 1) % 4
    h = [xs[i], as[j] - xs[j]].min
    xs[i] -= h
    xs[j] += h
end

puts xs.join(" ")
0