結果

問題 No.253 ロウソクの長さ
ユーザー simansiman
提出日時 2021-01-11 15:59:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 423 bytes
コンパイル時間 53 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 31,556 KB
平均クエリ数 21.72
最終ジャッジ日時 2023-09-24 02:50:20
合計ジャッジ時間 5,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
31,132 KB
testcase_01 AC 99 ms
30,868 KB
testcase_02 AC 102 ms
31,460 KB
testcase_03 AC 102 ms
30,592 KB
testcase_04 AC 102 ms
30,660 KB
testcase_05 AC 102 ms
31,348 KB
testcase_06 AC 102 ms
30,832 KB
testcase_07 AC 103 ms
30,936 KB
testcase_08 AC 102 ms
30,852 KB
testcase_09 AC 102 ms
31,356 KB
testcase_10 AC 101 ms
31,108 KB
testcase_11 AC 101 ms
31,164 KB
testcase_12 AC 103 ms
30,984 KB
testcase_13 AC 104 ms
31,224 KB
testcase_14 AC 103 ms
31,240 KB
testcase_15 AC 103 ms
31,364 KB
testcase_16 AC 104 ms
31,312 KB
testcase_17 AC 103 ms
31,556 KB
testcase_18 AC 106 ms
31,336 KB
testcase_19 AC 104 ms
30,840 KB
testcase_20 AC 104 ms
30,984 KB
testcase_21 AC 101 ms
31,368 KB
testcase_22 AC 104 ms
30,780 KB
testcase_23 AC 105 ms
31,348 KB
testcase_24 AC 103 ms
30,732 KB
testcase_25 AC 105 ms
31,088 KB
testcase_26 AC 105 ms
30,996 KB
testcase_27 AC 103 ms
31,200 KB
testcase_28 AC 102 ms
31,204 KB
testcase_29 AC 103 ms
31,464 KB
testcase_30 AC 103 ms
30,996 KB
testcase_31 AC 103 ms
31,308 KB
testcase_32 AC 103 ms
30,952 KB
testcase_33 AC 103 ms
30,840 KB
testcase_34 AC 104 ms
31,048 KB
testcase_35 AC 103 ms
30,552 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def query(y)
  STDOUT.puts("? #{y}")
  STDOUT.flush
  gets.chomp.to_i
end

res = query(100)

if res == 0
  puts "! 100"
  exit
elsif res < 0
  ok = 0
  ng = 100
else
  ok = 100
  ng = 10 ** 9 + 1
end

99.times do |i|
  y = (ok + ng) / 2
  res = query(y)

  if res == 0
    STDOUT.puts("! #{y + i + 1}")
    STDOUT.flush
    break
  elsif res < 0
    ng = y
    ok = [0, ok - 1].max
  else
    ok = [0, y - 1].max
  end
end
0