結果

問題 No.2085 Directed Complete Graph
ユーザー 👑 obakyan
提出日時 2022-09-27 22:49:13
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 25,580 KB
平均クエリ数 2533.76
最終ジャッジ日時 2024-12-22 17:15:47
合計ジャッジ時間 3,675 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

local gc = 0
local t = {}
local function query(a, b)
  io.write("? " .. a .. " " .. b .. "\n")
  io.flush()
  -- do
    -- gc = gc + 1
    -- if b == t[1] then return false end
    -- if a == t[#t] then return false end
    -- return false
  -- end
  local ret = io.read("*l")
  return tonumber(ret) == 1
end

local n = io.read("*n", "*l")

local f = query(1, 2)
if f then
  table.insert(t, 1)
  table.insert(t, 2)
else
  table.insert(t, 2)
  table.insert(t, 1)
end
for i = 3, n do
  if false and query(i, t[1]) then
    table.insert(t, 1, i)
  elseif false and query(t[#t], i) then
    table.insert(t, i)
  else
    local left, right = 0, #t + 1
    while 1 < right - left do
      local mid = math.floor((left + right) / 2)
      if query(i, t[mid]) then
        right = mid
      else
        left = mid
      end
    end
    table.insert(t, right, i)
  end
end
-- print("GC", gc)
io.write("!\n")
io.write(n - 1 .. "\n")
io.write(table.concat(t, " ") .. "\n")
io.flush()
0