結果

問題 No.1935 Water Simulation
ユーザー 👑 obakyanobakyan
提出日時 2022-05-15 11:07:03
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 5,392 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-01 06:03:45
合計ジャッジ時間 1,487 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local v1, v2, v3, v4, n = io.read():match("(%d+) (%d+) (%d+) (%d+) (%d+)")
v1 = tonumber(v1)
v2 = tonumber(v2)
v3 = tonumber(v3)
v4 = tonumber(v4)
n = lltonumber(n)
local a = {v1, 0, 0, 0}
local t = {}
local function push(day)
  local z = a[1] + a[2] * 101 + a[3] * 101 * 101
  t[z] = day
end
local function check()
  local z = a[1] + a[2] * 101 + a[3] * 101 * 101
  return t[z]
end
local day = 0LL
push(day)
while day < n do
  day = day + 1LL
  if day % 4LL == 1LL then
    local d = mmi(a[1], v2 - a[2])
    a[1] = a[1] - d
    a[2] = a[2] + d
  elseif day % 4LL == 2LL then
    local d = mmi(a[2], v3 - a[3])
    a[2] = a[2] - d
    a[3] = a[3] + d
  elseif day % 4LL == 3LL then
    local d = mmi(a[3], v4 - a[4])
    a[3] = a[3] - d
    a[4] = a[4] + d
  else
    local d = mmi(a[4], v1 - a[1])
    a[4] = a[4] - d
    a[1] = a[1] + d
  end
  if day % 4LL == 0LL then
    local tmp = check()
    if tmp then
      local len = day - tmp
      local rem = n - day
      local warp_day = day + (rem / len) * len
      day = warp_day
      t = {}
    else
      push(day)
    end
  end
end
print(table.concat(a, " "))
0