結果

問題 No.594 壊れた宝物発見機
ユーザー むらためむらため
提出日時 2019-01-27 17:21:46
言語 Nim
(2.0.2)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 4,238 ms
コンパイル使用メモリ 70,628 KB
実行使用メモリ 24,288 KB
平均クエリ数 71.25
最終ジャッジ日時 2023-09-23 16:45:50
合計ジャッジ時間 6,318 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
23,376 KB
testcase_01 AC 104 ms
24,168 KB
testcase_02 AC 100 ms
23,196 KB
testcase_03 AC 103 ms
23,316 KB
testcase_04 AC 100 ms
23,940 KB
testcase_05 AC 100 ms
23,796 KB
testcase_06 AC 100 ms
23,460 KB
testcase_07 AC 103 ms
23,760 KB
testcase_08 AC 104 ms
23,352 KB
testcase_09 AC 100 ms
24,240 KB
testcase_10 AC 98 ms
23,940 KB
testcase_11 AC 100 ms
23,376 KB
testcase_12 AC 103 ms
23,988 KB
testcase_13 AC 98 ms
23,772 KB
testcase_14 AC 103 ms
24,228 KB
testcase_15 AC 100 ms
24,288 KB
testcase_16 AC 98 ms
23,376 KB
testcase_17 AC 100 ms
24,288 KB
testcase_18 AC 98 ms
23,940 KB
testcase_19 AC 100 ms
23,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 27) Warning: imported and not used: 'math' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import sequtils,algorithm,math,tables,sugar
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord


proc request(x,y,z:int):int =
  echo "? ",x," ",y," ",z
  # let a = (x:37,y: -150,z:40)
  # return (a.x-x)*(a.x-x)+(a.y-y)*(a.y-y)+(a.z-z)*(a.z-z) * 5 + 10
  return scan()
proc decide(x,y,z:int) =
  echo "! ",x," ",y," ",z
  quit(0)

proc decideVal(request:proc(x:int):int) : int =
  var ax = -150
  var bx = 150
  var answers = newTable[int,int]()
  proc req(x:int) :int =
    if x in answers : return answers[x]
    answers[x] = request(x)
    return answers[x]
  while true:
    let mx = (ax + bx) div 2
    var ad = req(ax)
    var bd = req(bx)
    let md = req(mx)
    if md < ad :
      ax = (mx + ax) div 2
    if md < bd :
      bx = (mx + bx) div 2
    if bx - ax == 0 : return ax
    if bx - ax == 1:
      if req(ax) < req(bx) : return ax
      return bx
    if bx - ax <= 3:
      let A = toSeq(ax..bx).mapIt((it,req(it)))
      let dMin = A.mapIt(it[1]).min()
      for a in A:
        if a[1] == dMin: return a[0]

var (x,y,z) = (0,0,0)
x = decideVal( x => request(x,y,z))
y = decideVal( y => request(x,y,z))
z = decideVal( z => request(x,y,z))
decide(x,y,z)
0