結果

問題 No.1830 Balanced Majority
ユーザー 👑 obakyanobakyan
提出日時 2022-09-27 12:59:20
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 5,380 KB
実行使用メモリ 24,408 KB
平均クエリ数 7.54
最終ジャッジ日時 2023-08-24 03:49:19
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,264 KB
testcase_01 AC 24 ms
24,024 KB
testcase_02 AC 25 ms
24,000 KB
testcase_03 AC 23 ms
23,832 KB
testcase_04 AC 24 ms
23,868 KB
testcase_05 AC 23 ms
23,460 KB
testcase_06 AC 24 ms
24,336 KB
testcase_07 AC 26 ms
23,436 KB
testcase_08 AC 26 ms
23,424 KB
testcase_09 AC 25 ms
23,412 KB
testcase_10 AC 26 ms
23,472 KB
testcase_11 AC 26 ms
24,012 KB
testcase_12 AC 26 ms
23,460 KB
testcase_13 AC 27 ms
23,868 KB
testcase_14 AC 26 ms
23,544 KB
testcase_15 AC 27 ms
23,832 KB
testcase_16 AC 26 ms
23,376 KB
testcase_17 AC 27 ms
24,348 KB
testcase_18 AC 26 ms
24,300 KB
testcase_19 AC 26 ms
24,408 KB
testcase_20 AC 24 ms
23,712 KB
testcase_21 AC 27 ms
24,096 KB
testcase_22 AC 26 ms
23,472 KB
testcase_23 AC 26 ms
23,832 KB
testcase_24 AC 26 ms
24,096 KB
testcase_25 AC 24 ms
23,628 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 + 1, 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 + 1, n)
    end
  else
    if mv * lv < 0 then
      right = mid
    else
      left = mid
    end
  end
end
assert(false)
0