結果

問題 No.133 カードゲーム
ユーザー 👑 obakyanobakyan
提出日時 2019-05-04 00:54:54
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,124 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 5,372 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 08:40:50
合計ジャッジ時間 1,613 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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