結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
31,164 KB
testcase_01 AC 109 ms
31,016 KB
testcase_02 AC 105 ms
30,888 KB
testcase_03 AC 105 ms
31,008 KB
testcase_04 AC 105 ms
30,776 KB
testcase_05 AC 106 ms
31,296 KB
testcase_06 AC 106 ms
30,976 KB
testcase_07 AC 108 ms
30,720 KB
testcase_08 AC 108 ms
31,448 KB
testcase_09 AC 108 ms
31,088 KB
testcase_10 AC 109 ms
30,992 KB
testcase_11 WA -
testcase_12 AC 106 ms
31,088 KB
testcase_13 AC 107 ms
30,800 KB
testcase_14 AC 108 ms
31,128 KB
testcase_15 AC 109 ms
30,896 KB
testcase_16 AC 108 ms
31,108 KB
testcase_17 AC 108 ms
31,284 KB
testcase_18 AC 107 ms
30,852 KB
testcase_19 AC 106 ms
30,496 KB
testcase_20 WA -
testcase_21 AC 107 ms
31,324 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 108 ms
31,464 KB
testcase_25 AC 105 ms
30,824 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 < 0 && s < 0
    l = k
  elsif s_1 > 0 && s < 0
    r = k
  elsif s_n_1 < 0 && s < 0
    r = k
  elsif s_n_1 < 0 && s > 0
    l = k
  end
end
0