結果

問題 No.850 企業コンテスト2位
ユーザー nimonnimon
提出日時 2019-08-31 00:25:55
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,046 bytes
コンパイル時間 3,206 ms
コンパイル使用メモリ 71,000 KB
実行使用メモリ 24,480 KB
平均クエリ数 197.75
最終ジャッジ日時 2023-09-23 18:11:54
合計ジャッジ時間 9,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 24 ms
24,048 KB
testcase_02 AC 23 ms
23,688 KB
testcase_03 AC 23 ms
23,856 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 22 ms
24,336 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 22 ms
23,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

proc ask(x, y: int): int =
  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]))

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