結果
問題 | No.355 数当てゲーム(2) |
ユーザー | 👑 obakyan |
提出日時 | 2020-04-11 22:08:25 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,028 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 6,684 KB |
実行使用メモリ | 25,464 KB |
平均クエリ数 | 92.81 |
最終ジャッジ日時 | 2024-07-17 03:25:42 |
合計ジャッジ時間 | 9,132 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 26 ms
24,580 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | AC | 25 ms
24,836 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | AC | 25 ms
25,220 KB |
testcase_10 | AC | 26 ms
25,220 KB |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 26 ms
25,220 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 26 ms
24,836 KB |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | AC | 27 ms
25,436 KB |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
ソースコード
local mfl, mce = math.floor, math.ceil local function ask(tbl) io.write(table.concat(tbl, " ")) io.write("\n") io.flush() local ret = io.read() local hit, blow = ret:match("(%d) (%d)") hit, blow = tonumber(hit), tonumber(blow) return hit, blow end local function combination_get_map(n) local combmap = {} for i = 1, n do combmap[i] = {} local ret = 1 for j = 1, i do ret = mfl(ret * (i + 1 - j) / j) combmap[i][j] = ret end end return combmap end local function combination_get_count(combmap, n, k) if k < 0 then return 0 elseif n < k then return 0 elseif k == 0 then return 1 else return combmap[n][k] end end local function combination_get_array(combmap, n, k, idx) local rem = k local retary = {} for i = 1, n do local useCnt = combination_get_count(combmap, n - i, rem - 1) local unuseCnt = combination_get_count(combmap, n - i, rem) if idx <= useCnt then rem = rem - 1 table.insert(retary, i) else idx = idx - useCnt end end return retary end local cmap = combination_get_map(10) local cand = {} for i = 1, 210 do local ary = combination_get_array(cmap, 10, 4, i) for j = 1, 4 do ary[j] = ary[j] - 1 end local h, b = ask(ary) if h + b == 4 then for j = 1, 4 do cand[j] = ary[j] end break end end local function getpattern(n, patall, idx) local used = {} local retary = {} local div = patall for i = 1, n do used[i] = false end for i = n, 1, -1 do div = mfl(div / i) local v_idx = mfl(idx / div) idx = idx % div local tmp_idx = 0 for j = 1, n do if not used[j] then if tmp_idx == v_idx then table.insert(retary, j) used[j] = true break else tmp_idx = tmp_idx + 1 end end end end return retary end for ip = 0, 23 do local idxary = getpattern(4, 24, ip) local z = {} for j = 1, 4 do z[j] = cand[idxary[j]] end local h, b = ask(z) if h == 4 then break end end