結果

問題 No.425 ジャンケンの必勝法
ユーザー 👑 obakyanobakyan
提出日時 2021-08-12 23:19:38
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 7,072 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 04:15:03
合計ジャッジ時間 1,152 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local p0, q = io.read("*n", "*n")
local mat = {}
for i = 1, 101 do
  mat[i] = {}
  for j = 1, 101 do
    mat[i][j] = 0
  end
end
local vec = {}

--[[
f(p) = p * 1/2 + p * 1/2 * f(p - q) + (1-p) * 1/3 + (1-p) * 1/3 * f(p + q)
f(p) - p/2 * f(p-q) - (1-p)/3 * f(p+q) = 1/3 + p/6
]]
for p = 0, 100 do
  local left = p - q
  if left < 0 then left = 0 end
  local right = p + q
  if 100 < right then right = 100 end
  local r = p / 100
  mat[p + 1][p + 1] = mat[p + 1][p + 1] + 1
  mat[p + 1][left + 1] = mat[p + 1][left + 1] + (-r / 2)
  mat[p + 1][right + 1] = mat[p + 1][right + 1] + (-(1 - r) / 3)
  vec[p + 1] = 1 / 3 + r / 6
end

for i = 1, 101 do
  local base = mat[i][i]
  for k = i, 101 do
    mat[i][k] = mat[i][k] / base
  end
  vec[i] = vec[i] / base
  for j = i + 1, 101 do
    local mul = mat[j][i]
    for k = i, 101 do
      mat[j][k] = mat[j][k] - mul * mat[i][k]
    end
    vec[j] = vec[j] - mul * vec[i]
  end
end
for i = 101, 1, -1 do
  for j = i - 1, 1, -1 do
    vec[j] = vec[j] - mat[j][i] * vec[i]
  end
end

print((1 + vec[p0 + 1]) / 3)
0