結果

問題 No.1688 Veterinarian
ユーザー 👑 obakyanobakyan
提出日時 2022-03-21 21:25:33
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 252 ms / 3,000 ms
コード長 1,472 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 6,940 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 18:07:44
合計ジャッジ時間 2,670 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,820 KB
testcase_01 AC 252 ms
6,944 KB
testcase_02 AC 68 ms
6,940 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 AC 9 ms
6,944 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 AC 251 ms
6,944 KB
testcase_07 AC 9 ms
6,944 KB
testcase_08 AC 250 ms
6,940 KB
testcase_09 AC 246 ms
6,940 KB
testcase_10 AC 167 ms
6,940 KB
testcase_11 AC 117 ms
6,940 KB
testcase_12 AC 13 ms
6,940 KB
testcase_13 AC 132 ms
6,944 KB
testcase_14 AC 38 ms
6,940 KB
testcase_15 AC 232 ms
6,944 KB
testcase_16 AC 43 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local function encode(a, b, c)
  return a + (b - 1) * 50 + (c - 1) * 2500
end
local function decode(idx)
  local c = mce(idx / 2500)
  idx = idx - (c - 1) * 2500
  local b = mce(idx / 50)
  local a = idx - (b - 1) * 50
  return a, b, c
end

local tot = encode(50, 50, 50)
local fa, fb, fc, n = io.read("*n", "*n", "*n", "*n")
local dp1, dp2 = {}, {}
for i = 1, tot do
  dp1[i] = 0
end
dp1[encode(fa, fb, fc)] = 1
for i = 1, n do
  local src = i % 2 == 1 and dp1 or dp2
  local dst = i % 2 == 1 and dp2 or dp1
  for j = 1, tot do
    dst[j] = 0
  end
  for j = 1, tot do
    local a, b, c = decode(j)
    local rate = 0
    local sum = a + b + c
    if 1 < a then
      local z = a * (a - 1) / sum / (sum - 1)
      rate = rate + z
      local d = encode(a - 1, b, c)
      dst[d] = dst[d] + src[j] * z
    end
    if 1 < b then
      local z = b * (b - 1) / sum / (sum - 1)
      rate = rate + z
      local d = encode(a, b - 1, c)
      dst[d] = dst[d] + src[j] * z
    end
    if 1 < c then
      local z = c * (c - 1) / sum / (sum - 1)
      rate = rate + z
      local d = encode(a, b, c - 1)
      dst[d] = dst[d] + src[j] * z
    end
    dst[j] = dst[j] + src[j] * (1 - rate)
  end
end
local aa, ab, ac = 0, 0, 0
local tbl = n % 2 == 1 and dp2 or dp1
for i = 1, tot do
  local a, b, c = decode(i)
  aa = aa + (fa - a) * tbl[i]
  ab = ab + (fb - b) * tbl[i]
  ac = ac + (fc - c) * tbl[i]
end
print(aa .. " " .. ab .. " " .. ac)
0