結果

問題 No.1830 Balanced Majority
ユーザー 👑 obakyanobakyan
提出日時 2022-09-27 12:53:12
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 670 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 24,432 KB
平均クエリ数 16.81
最終ジャッジ日時 2023-08-24 03:48:45
合計ジャッジ時間 4,006 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

local n = io.read("*n", "*l")
local left, right = 2, n - 1
local lv = query(left)
local rv = query(right)
if lv == rv then
  ans(left, right)
end
local hn = math.floor(n / 2)
for i = 1, 18 do
  local mid = math.floor((left + right) / 2)
  local mv = query(mid)
  if mv == 0 then
    if hn <= mid then
      ans(1, mid)
    else
      ans(mid, n)
    end
  else
    if mv * lv < 0 then
      right = mid
    else
      left = mid
    end
  end
end
0