結果

問題 No.850 企業コンテスト2位
ユーザー nimonnimon
提出日時 2019-08-31 00:28:07
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 1,123 bytes
コンパイル時間 3,211 ms
コンパイル使用メモリ 70,980 KB
実行使用メモリ 24,504 KB
平均クエリ数 199.00
最終ジャッジ日時 2023-09-23 18:11:34
合計ジャッジ時間 7,195 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,748 KB
testcase_01 AC 26 ms
23,388 KB
testcase_02 AC 27 ms
23,448 KB
testcase_03 AC 27 ms
23,952 KB
testcase_04 AC 27 ms
24,264 KB
testcase_05 RE -
testcase_06 AC 25 ms
23,340 KB
testcase_07 AC 29 ms
23,952 KB
testcase_08 AC 32 ms
24,360 KB
testcase_09 AC 33 ms
24,252 KB
testcase_10 AC 37 ms
23,964 KB
testcase_11 RE -
testcase_12 AC 37 ms
23,292 KB
testcase_13 AC 36 ms
24,264 KB
testcase_14 RE -
testcase_15 AC 36 ms
24,048 KB
testcase_16 RE -
testcase_17 AC 37 ms
23,460 KB
testcase_18 AC 36 ms
23,580 KB
testcase_19 AC 37 ms
23,556 KB
testcase_20 RE -
testcase_21 AC 37 ms
24,312 KB
testcase_22 AC 38 ms
23,844 KB
testcase_23 AC 36 ms
23,736 KB
testcase_24 AC 38 ms
23,676 KB
testcase_25 RE -
testcase_26 AC 37 ms
23,364 KB
testcase_27 AC 27 ms
23,556 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]))
  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