結果

問題 No.850 企業コンテスト2位
ユーザー chaemonchaemon
提出日時 2019-08-30 00:04:22
言語 Nim
(2.2.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 4,320 ms
コンパイル使用メモリ 73,636 KB
実行使用メモリ 25,476 KB
平均クエリ数 200.07
最終ジャッジ日時 2024-07-16 18:03:11
合計ジャッジ時間 7,117 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 37) Warning: imported and not used: 'macros' [UnusedImport]
/home/judge/data/code/Main.nim(2, 19) Warning: imported and not used: 'sequtils' [UnusedImport]
/home/judge/data/code/Main.nim(2, 29) Warning: imported and not used: 'tables' [UnusedImport]

ソースコード

diff #

#{{{ header
import algorithm, sequtils, tables, macros, math, sets, strutils, deques
when defined(MYDEBUG):
  import header

import deques
var cin = initDeque[string]()
proc get(cin:var Deque[string]):string =
  while cin.len == 0:
    for s in stdin.readLine.split(' '):
      if s.len > 0: cin.addLast(s)
  return cin.popFirst
proc nextInt(cin:var Deque[string]):int = cin.get.parseInt
proc nextFloat(cin:var Deque[string]):float = cin.get.parseFloat
proc nextString(cin:var Deque[string]):string = cin.get

template `max=`*(x,y:typed):void = x = max(x,y)
template `min=`*(x,y:typed):void = x = min(x,y)
template infty(T): untyped = ((T(1) shl T(sizeof(T)*8-2)) - 1)
#}}}

proc test(x,y:int):int =
  echo "? ",x," ",y
  let ans = cin.nextInt()
  return ans

proc main() =
  let N = cin.nextInt()
  var v = initDeque[(int,seq[int])]()
  for i in 1..N: v.addLast((i,@[]))
  while v.len > 1:
    var v2 = initDeque[(int,seq[int])]()
    while v.len > 0:
      if v.len == 1: v2.addLast(v.popLast)
      else:
        var s,t = v.popLast
        let r = test(s[0],t[0])
        if r == s[0]:
          s[1].add(t[0])
          v2.addLast(s)
        else:
          t[1].add(s[0])
          v2.addLast(t)
    v = v2
  var w = v.popFirst[1]
  var cur = w[0]
  for i in 1..<w.len:
    cur = test(cur,w[i])
  echo "! ",cur
  discard

main()
0