結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,388 KB
testcase_01 AC 24 ms
24,360 KB
testcase_02 AC 24 ms
24,036 KB
testcase_03 AC 24 ms
23,448 KB
testcase_04 AC 24 ms
23,400 KB
testcase_05 AC 24 ms
23,652 KB
testcase_06 AC 24 ms
23,676 KB
testcase_07 AC 26 ms
24,348 KB
testcase_08 AC 24 ms
23,712 KB
testcase_09 AC 27 ms
24,048 KB
testcase_10 AC 26 ms
23,676 KB
testcase_11 WA -
testcase_12 AC 26 ms
23,664 KB
testcase_13 AC 26 ms
23,412 KB
testcase_14 AC 27 ms
24,312 KB
testcase_15 AC 27 ms
24,384 KB
testcase_16 AC 26 ms
24,060 KB
testcase_17 AC 26 ms
23,376 KB
testcase_18 AC 24 ms
24,312 KB
testcase_19 AC 25 ms
23,652 KB
testcase_20 AC 24 ms
23,436 KB
testcase_21 AC 25 ms
24,408 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 25 ms
24,060 KB
testcase_25 AC 24 ms
23,568 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, n)
    end
  else
    if mv * lv < 0 then
      right = mid
    else
      left = mid
    end
  end
end
0