結果

問題 No.850 企業コンテスト2位
ユーザー nimon
提出日時 2019-08-31 00:31:15
言語 Nim
(2.2.0)
結果
RE  
実行時間 -
コード長 1,193 bytes
コンパイル時間 2,983 ms
コンパイル使用メモリ 66,424 KB
実行使用メモリ 25,484 KB
平均クエリ数 199.00
最終ジャッジ日時 2024-07-16 18:06:07
合計ジャッジ時間 6,550 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

from strutils import parseInt
from sequtils import mapIt, newSeqWith
from algorithm import binarySearch

var askCount = 0
proc ask(x, y: int): int =
  askCount.inc
  if askCount > 334:
    echo "! ", x
  echo "? ", x, " ", y
  result = stdin.readLine.parseInt

proc ans(x: int) =
  echo "! ", x


let N = stdin.readLine.parseInt

var histories = newSeqWith(10, newSeq[int]())
histories[0] = (1..N).mapIt(it)

for h in 0..<9:
  if histories[h].len == 1: break
  for i in countup(1, histories[h].high, 2):
    histories[h + 1].add(ask(histories[h][i - 1], histories[h][i]))
  if histories[h].len mod 2 == 1:
    histories[h + 1].add(histories[h][^1])

var
  results = newSeq[int]()
  max: int
for h in countdown(9, 0):
  if histories[h].len == 0:
    continue
  if histories[h].len == 1:
    max = histories[h][0]
    continue
  let i = histories[h].binarySearch(max)
  if i mod 2 == 0:
    results.add(histories[h][i + 1])
  else:
    results.add(histories[h][i - 1])

while results.len > 1:
  var next = newSeq[int]()
  for i in countup(1, results.high, 2):
    next.add(ask(results[i - 1], results[i]))
  if results.len mod 2 == 1:
    next.add(results[^1])
  results = next

ans(results[0])
0