結果

問題 No.850 企業コンテスト2位
ユーザー 👑 obakyanobakyan
提出日時 2020-11-30 22:36:46
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 24,372 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-24 07:20:22
合計ジャッジ時間 2,737 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
24,096 KB
testcase_01 AC 25 ms
24,060 KB
testcase_02 AC 25 ms
23,688 KB
testcase_03 AC 25 ms
23,412 KB
testcase_04 AC 25 ms
23,640 KB
testcase_05 AC 25 ms
23,700 KB
testcase_06 AC 24 ms
23,832 KB
testcase_07 AC 29 ms
24,312 KB
testcase_08 AC 31 ms
23,388 KB
testcase_09 AC 31 ms
23,376 KB
testcase_10 AC 36 ms
24,048 KB
testcase_11 AC 36 ms
24,060 KB
testcase_12 AC 36 ms
23,664 KB
testcase_13 AC 36 ms
23,844 KB
testcase_14 AC 36 ms
24,060 KB
testcase_15 AC 35 ms
23,616 KB
testcase_16 AC 35 ms
23,448 KB
testcase_17 AC 35 ms
24,372 KB
testcase_18 AC 35 ms
23,412 KB
testcase_19 AC 35 ms
24,348 KB
testcase_20 AC 35 ms
23,508 KB
testcase_21 AC 35 ms
23,424 KB
testcase_22 AC 36 ms
24,036 KB
testcase_23 AC 36 ms
23,664 KB
testcase_24 AC 36 ms
23,460 KB
testcase_25 AC 36 ms
23,532 KB
testcase_26 AC 36 ms
23,580 KB
testcase_27 AC 25 ms
24,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local function query(a, b)
  io.write("? " .. a .. " " .. b .. "\n")
  io.flush()
  local ret = io.read("*l")
  return tonumber(ret)
end
local function ans(a)
  io.write("! " .. a .. "\n")
  io.flush()
end

local n = io.read()
n = tonumber(n)
local t = {}
local d = {}
d[1] = {}
for i = 1, n do
  t[i] = {}
  d[1][i] = i
end

local stage = 1
while 1 < #d[stage] do
  d[stage + 1] = {}
  for i = 1, #d[stage], 2 do
    if i ~= #d[stage] then
      local v1, v2 = d[stage][i], d[stage][i + 1]
      local ret = query(v1, v2)
      table.insert(d[stage + 1], ret)
      if v1 == ret then
        table.insert(t[v1], v2)
      else
        table.insert(t[v2], v1)
      end
    else
      table.insert(d[stage + 1], d[stage][i])
    end
  end
  stage = stage + 1
end
local top = d[stage][1]
local second = t[top][1]
for i = 2, #t[top] do
  local v = t[top][i]
  local ret = query(second, v)
  second = ret
end
ans(second)
0