結果

問題 No.813 ユキちゃんの冒険
ユーザー 👑 obakyanobakyan
提出日時 2019-04-13 00:49:52
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,292 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 07:20:48
合計ジャッジ時間 2,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 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,292 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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

tgt_r = s
tgt_l = t
prv_r = r
prv_l = 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