結果
問題 | No.133 カードゲーム |
ユーザー |
👑 |
提出日時 | 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 |
ソースコード
local ior = io.input()local n = ior:read("*n")local a, b = {}, {}for i = 1, n do a[i] = ior:read("*n") endfor i = 1, n do b[i] = ior:read("*n") endlocal tot = 1for i = 2, n do tot = tot * i endlocal wincnt = 0local function getcard(idx, tbl)local ret = {}local box = {}for i = 1, n do box[i] = true endfor i = n, 1, -1 dolocal dv = 1for k = 1, i - 1 dodv = dv * kendlocal tgt = math.floor(idx / dv)local i_tgt = 0for j = 1, n doif(box[j]) thenif(tgt == i_tgt) thentable.insert(ret, tbl[j])box[j] = falsebreakelsei_tgt = i_tgt + 1endendendidx = idx % dvendreturn retendfor i_match = 0, tot * tot - 1 dolocal i_a = i_match % totlocal i_b = math.floor(i_match / tot)ac = getcard(i_a, a)bc = getcard(i_b, b)local score = 0for i = 1, n doif(bc[i] < ac[i]) then score = score + 1elseif(ac[i] < bc[i]) then score = score - 1 endendif(0 < score) thenwincnt = wincnt + 1endendprint(string.format("%.8f", wincnt / (tot * tot)))