結果

問題 No.1830 Balanced Majority
ユーザー simansiman
提出日時 2022-02-05 15:14:28
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 563 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 11,564 KB
実行使用メモリ 31,628 KB
平均クエリ数 17.50
最終ジャッジ日時 2023-09-02 06:44:00
合計ジャッジ時間 4,885 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 104 ms
30,628 KB
testcase_02 WA -
testcase_03 AC 104 ms
30,964 KB
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 AC 107 ms
30,792 KB
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

def send_query(k)
  STDOUT.puts("? #{k}")
  STDOUT.flush

  gets.to_i
end

s_1 = send_query(1)
s_n_1 = send_query(N - 1)

if s_1 == s_n_1
  puts "! #{2} #{N - 1}"
  exit
end

l = 2
r = N - 1

18.times do
  k = (l + r) / 2
  s = send_query(k)
  rs = k - s
  diff = s - rs

  if diff == 0
    if k < N / 2
      puts "! #{k + 1} #{N}"
    else
      puts "! 1 #{k}"
    end

    exit
  elsif s_1 < 0 && diff < 0
    l = k
  elsif s_1 > 0 && diff < 0
    r = k
  elsif s_n_1 < 0 && diff < 0
    r = k
  elsif s_n_1 < 0 && diff > 0
    l = k
  end
end
0