結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 83 ms
15,040 KB
testcase_04 AC 83 ms
15,088 KB
testcase_05 AC 89 ms
15,320 KB
testcase_06 WA -
testcase_07 AC 83 ms
15,300 KB
testcase_08 AC 83 ms
15,184 KB
testcase_09 AC 84 ms
15,360 KB
testcase_10 AC 83 ms
15,328 KB
testcase_11 AC 84 ms
15,136 KB
testcase_12 AC 84 ms
15,332 KB
testcase_13 AC 83 ms
15,076 KB
testcase_14 AC 83 ms
15,076 KB
testcase_15 AC 85 ms
15,124 KB
testcase_16 AC 83 ms
15,240 KB
testcase_17 AC 83 ms
15,244 KB
testcase_18 AC 84 ms
15,044 KB
testcase_19 AC 82 ms
15,268 KB
testcase_20 AC 82 ms
15,080 KB
testcase_21 AC 82 ms
15,148 KB
testcase_22 AC 83 ms
15,044 KB
testcase_23 AC 82 ms
15,348 KB
testcase_24 AC 83 ms
15,240 KB
testcase_25 AC 82 ms
15,072 KB
testcase_26 AC 83 ms
15,036 KB
testcase_27 AC 84 ms
15,164 KB
testcase_28 AC 82 ms
15,156 KB
testcase_29 AC 83 ms
15,044 KB
testcase_30 AC 83 ms
15,268 KB
testcase_31 AC 83 ms
15,280 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