結果

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

テストケース

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

ソースコード

diff #

local function query(num)
  io.write("? " .. num .. "\n")
  io.flush()
  local ret = io.read("*l")
  ret = tonumber(ret)
  local a_minus_b = ret - (num - ret)
  return a_minus_b
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 = 1, 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