結果

問題 No.813 ユキちゃんの冒険
ユーザー 👑 obakyanobakyan
提出日時 2019-04-16 13:23:16
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,398 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 07:22:26
合計ジャッジ時間 2,549 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local n = io.read("*n")
local p, q = io.read("*n", "*n")

r, l = {}, {}
for i = 0, n+1 do
  r[i], l[i] = 0, 0
end
r[1] = 1

local rem = 1
local genten = r[1] * p
local migi = 0
local sinda = 0

local s, t = {}, {}
s[0] = 0
t[0] = 0
s[n+1] = 0
t[n+1] = 0

local tgt_r, tgt_l, prv_r, prv_l = s, t, r, l
while(0.001 <= rem) do
  for i = 1, n do
    tgt_r[i] = prv_r[i - 1] * q + prv_l[i - 1] * p
    tgt_l[i] = prv_l[i + 1] * q + prv_r[i + 1] * p
    sinda = sinda + (prv_r[i] + prv_l[i]) * (1 - p - q)
  end
  genten = genten + prv_l[1] * q
  migi = migi + prv_r[n] * q
  rem = 1 - sinda - genten - migi

  if(tgt_r == s) then
    tgt_r, tgt_l, prv_r, prv_l = r, l, s, t
  else
    tgt_r, tgt_l, prv_r, prv_l = s, t, r, l
  end
end
print(genten)

0