結果

問題 No.1830 Balanced Majority
ユーザー simansiman
提出日時 2022-02-05 15:19:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 11,268 KB
実行使用メモリ 31,496 KB
平均クエリ数 7.42
最終ジャッジ日時 2023-09-02 06:44:18
合計ジャッジ時間 5,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
30,816 KB
testcase_01 AC 103 ms
30,784 KB
testcase_02 AC 103 ms
31,140 KB
testcase_03 AC 103 ms
31,344 KB
testcase_04 AC 104 ms
30,904 KB
testcase_05 AC 104 ms
30,864 KB
testcase_06 AC 102 ms
30,908 KB
testcase_07 AC 107 ms
31,136 KB
testcase_08 AC 106 ms
30,828 KB
testcase_09 AC 107 ms
30,784 KB
testcase_10 AC 108 ms
30,864 KB
testcase_11 AC 106 ms
31,496 KB
testcase_12 AC 104 ms
31,104 KB
testcase_13 AC 107 ms
30,696 KB
testcase_14 AC 107 ms
30,980 KB
testcase_15 AC 109 ms
31,340 KB
testcase_16 AC 109 ms
30,880 KB
testcase_17 AC 107 ms
31,028 KB
testcase_18 AC 105 ms
31,160 KB
testcase_19 AC 104 ms
30,660 KB
testcase_20 AC 100 ms
31,204 KB
testcase_21 AC 107 ms
31,068 KB
testcase_22 AC 106 ms
31,040 KB
testcase_23 AC 108 ms
31,288 KB
testcase_24 AC 104 ms
31,216 KB
testcase_25 AC 102 ms
31,336 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

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

  s = gets.to_i
  rs = k - s

  s - rs
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)

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

    exit
  elsif s_1 * s < 0
    r = k
  elsif s_1 * s > 0
    l = k
  elsif s_n_1 * s < 0
    l = k
  elsif s_n_1 * x > 0
    r = k
  end
end
0