結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 23 ms
23,832 KB
testcase_02 AC 23 ms
23,616 KB
testcase_03 AC 23 ms
24,048 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 23 ms
24,024 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 25 ms
23,652 KB
testcase_13 AC 25 ms
23,424 KB
testcase_14 WA -
testcase_15 AC 26 ms
24,036 KB
testcase_16 AC 26 ms
24,048 KB
testcase_17 AC 25 ms
23,640 KB
testcase_18 AC 24 ms
24,024 KB
testcase_19 AC 23 ms
23,664 KB
testcase_20 AC 23 ms
23,376 KB
testcase_21 AC 25 ms
24,024 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 26 ms
23,544 KB
testcase_25 AC 23 ms
24,048 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 = 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