結果
問題 | No.850 企業コンテスト2位 |
ユーザー |
![]() |
提出日時 | 2019-08-31 00:42:59 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 3,293 ms |
コンパイル使用メモリ | 66,292 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 200.11 |
最終ジャッジ日時 | 2024-07-16 18:05:58 |
合計ジャッジ時間 | 5,976 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 |
ソースコード
from strutils import parseIntfrom sequtils import mapIt, newSeqWithfrom algorithm import binarySearchvar askCount = 0proc ask(x, y: int): int =askCount.incif askCount > 334:echo "! ", xquit()echo "? ", x, " ", yresult = stdin.readLine.parseIntproc ans(x: int) =echo "! ", xlet N = stdin.readLine.parseIntvar histories = newSeqWith(30, newSeq[int]())histories[0] = (1..N).mapIt(it)for h in 0..<25:if histories[h].len <= 1: breakfor 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])varresults = newSeq[int]()max: intfor h in countdown(20, 0):if histories[h].len == 0:continueif histories[h].len == 1:max = histories[h][0]continuelet i = histories[h].binarySearch(max)if i mod 2 == 0:if i + 1 <= histories[h].high: results.add(histories[h][i + 1])else:if i - 1 >= 0: 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 = nextans(results[0])