結果

問題 No.133 カードゲーム
ユーザー 👑 obakyanobakyan
提出日時 2019-05-04 00:54:54
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,124 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-01 17:57:31
合計ジャッジ時間 1,164 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

local ior = io.input()
local n = ior:read("*n")
local a, b = {}, {}
for i = 1, n do a[i] = ior:read("*n") end
for i = 1, n do b[i] = ior:read("*n") end
local tot = 1
for i = 2, n do tot = tot * i end
local wincnt = 0

local function getcard(idx, tbl)
  local ret = {}
  local box = {}
  for i = 1, n do box[i] = true end
  for i = n, 1, -1 do
    local dv = 1
    for k = 1, i - 1 do
      dv = dv * k
    end
    local tgt = math.floor(idx / dv)
    local i_tgt = 0
    for j = 1, n do
      if(box[j]) then
        if(tgt == i_tgt) then
          table.insert(ret, tbl[j])
          box[j] = false
          break
        else
          i_tgt = i_tgt + 1
        end
      end
    end
    idx = idx % dv
  end
  return ret
end

for i_match = 0, tot * tot - 1 do
  local i_a = i_match % tot
  local i_b = math.floor(i_match / tot)
  ac = getcard(i_a, a)
  bc = getcard(i_b, b)
  local score = 0
  for i = 1, n do
    if(bc[i] < ac[i]) then score = score + 1
    elseif(ac[i] < bc[i]) then score = score - 1 end
  end
  if(0 < score) then
    wincnt = wincnt + 1
  end
end
print(string.format("%.8f", wincnt / (tot * tot)))
0