結果

問題 No.75 回数の期待値の問題
ユーザー 👑 obakyanobakyan
提出日時 2019-04-24 09:39:02
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,043 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 5,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 04:20:01
合計ジャッジ時間 1,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

local k = io.read("*n")
k = k + 1
local t = {}
t[1] = 1
for i = 2, k do
  t[i] = 0
end
local rem = 1
local e = 0
local cnt = 0
while(0.00001 < rem) do
  cnt = cnt + 1
  -- GOAL
  local tmp = t[k - 1]
  if(2 < k) then tmp = tmp +  t[k - 2] end
  if(3 < k) then tmp = tmp +  t[k - 3] end
  if(4 < k) then tmp = tmp +  t[k - 4] end
  if(5 < k) then tmp = tmp +  t[k - 5] end
  if(6 < k) then tmp = tmp +  t[k - 6] end
  e = e + cnt * tmp / 6
  rem = rem - tmp / 6
  -- START
  local st = t[k - 1] * 5
  if(2 < k) then st = st + t[k - 2] * 4 end
  if(3 < k) then st = st + t[k - 3] * 3 end
  if(4 < k) then st = st + t[k - 4] * 2 end
  if(5 < k) then st = st + t[k - 5] end
  st = st / 6
  -- MID
  for i = k - 1, 2, -1 do
    t[i] = t[i - 1]
    if(2 < i) then t[i] = t[i] + t[i - 2] end
    if(3 < i) then t[i] = t[i] + t[i - 3] end
    if(4 < i) then t[i] = t[i] + t[i - 4] end
    if(5 < i) then t[i] = t[i] + t[i - 5] end
    if(6 < i) then t[i] = t[i] + t[i - 6] end
    t[i] = t[i] / 6
  end
  t[1] = st
end
print(string.format("%.8f", e))
0