結果

問題 No.1935 Water Simulation
ユーザー maguroflymagurofly
提出日時 2022-05-13 21:37:18
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 512 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 11,432 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-09-29 06:38:04
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 79 ms
15,356 KB
testcase_04 AC 76 ms
15,120 KB
testcase_05 AC 76 ms
15,084 KB
testcase_06 AC 75 ms
15,052 KB
testcase_07 AC 76 ms
15,304 KB
testcase_08 AC 82 ms
15,120 KB
testcase_09 AC 75 ms
15,136 KB
testcase_10 AC 76 ms
15,048 KB
testcase_11 AC 75 ms
15,016 KB
testcase_12 AC 75 ms
15,252 KB
testcase_13 AC 75 ms
15,044 KB
testcase_14 AC 76 ms
15,088 KB
testcase_15 AC 76 ms
15,096 KB
testcase_16 AC 79 ms
15,288 KB
testcase_17 AC 76 ms
15,276 KB
testcase_18 AC 77 ms
15,288 KB
testcase_19 AC 76 ms
15,304 KB
testcase_20 AC 76 ms
15,132 KB
testcase_21 AC 76 ms
15,248 KB
testcase_22 AC 75 ms
15,184 KB
testcase_23 AC 75 ms
15,116 KB
testcase_24 AC 75 ms
15,120 KB
testcase_25 AC 75 ms
15,152 KB
testcase_26 AC 77 ms
15,316 KB
testcase_27 AC 79 ms
15,120 KB
testcase_28 AC 81 ms
15,280 KB
testcase_29 AC 76 ms
15,120 KB
testcase_30 AC 75 ms
15,132 KB
testcase_31 AC 75 ms
15,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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