結果

問題 No.850 企業コンテスト2位
ユーザー simansiman
提出日時 2022-07-26 07:58:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 11,576 KB
実行使用メモリ 31,448 KB
平均クエリ数 200.07
最終ジャッジ日時 2023-09-22 23:25:05
合計ジャッジ時間 5,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
31,340 KB
testcase_01 AC 103 ms
30,904 KB
testcase_02 AC 103 ms
31,080 KB
testcase_03 AC 103 ms
31,232 KB
testcase_04 AC 102 ms
31,360 KB
testcase_05 AC 101 ms
30,916 KB
testcase_06 AC 102 ms
31,360 KB
testcase_07 AC 108 ms
31,152 KB
testcase_08 AC 111 ms
30,956 KB
testcase_09 AC 109 ms
30,820 KB
testcase_10 AC 115 ms
30,872 KB
testcase_11 AC 116 ms
31,448 KB
testcase_12 AC 114 ms
31,228 KB
testcase_13 AC 114 ms
31,256 KB
testcase_14 AC 116 ms
30,936 KB
testcase_15 AC 115 ms
31,128 KB
testcase_16 AC 113 ms
30,892 KB
testcase_17 AC 115 ms
31,100 KB
testcase_18 AC 114 ms
30,712 KB
testcase_19 AC 115 ms
30,832 KB
testcase_20 AC 115 ms
31,284 KB
testcase_21 AC 117 ms
30,896 KB
testcase_22 AC 116 ms
31,356 KB
testcase_23 AC 116 ms
30,656 KB
testcase_24 AC 116 ms
31,032 KB
testcase_25 AC 115 ms
31,360 KB
testcase_26 AC 118 ms
31,164 KB
testcase_27 AC 106 ms
31,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

def send_query(x, y)
  STDOUT.puts("? #{x} #{y}")
  STDOUT.flush
  gets.to_i
end

losers = Hash.new { |h, k| h[k] = [] }
winners = [*1..N]

while winners.size >= 2
  x, y = winners.shift(2)

  winner = send_query(x, y)

  winners << winner

  if x == winner
    losers[x] << y
  else
    losers[y] << x
  end
end

top = winners.first
winners = losers[top]

while winners.size >= 2
  x, y = winners.shift(2)

  winner = send_query(x, y)
  winners << winner
end

STDOUT.puts("! #{winners.first}")
STDOUT.flush
0