結果

問題 No.876 Range Compress Query
ユーザー むらためむらため
提出日時 2019-09-06 23:06:08
言語 Nim
(2.0.0)
結果
WA  
実行時間 -
コード長 4,631 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 66,468 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-15 12:52:33
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils
# import algorithm,math,times,bitops
# import tables,intsets,sets,queues
# import macros,strutils,sugar,heapqueue
# import rationals,critbits,ropes,nre,pegs,complex,stats
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)
template stopwatch(body) = (let t1 = cpuTime();body;stderr.writeLine "TIME:",(cpuTime() - t1) * 1000,"ms")
proc `^`(n:int) : int{.inline.} = (1 shl n)
#
template useUnsafeInput() =
  setStdIoUnbuffered()
  proc gets(str: untyped){.header: "<stdio.h>", varargs.}
  proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>",discardable .}
  proc scanf(formatstr: cstring){.header: "<stdio.h>", varargs.}
  proc scan(): int = scanf("%lld\n",addr result)
  proc scan(): int =
    while true:
      var k = getchar_unlocked()
      if k < '0' or k > '9': break
      result = 10 * result + k.ord - '0'.ord
  proc scan(): int =
    var minus = false
    block:
      let k = getchar_unlocked()
      if k == '-' : minus = true
      else: result = 10 * result + k.ord - '0'.ord
    while true:
      let k = getchar_unlocked()
      if k < '0' or k > '9': break
      result = 10 * result + k.ord - '0'.ord
    if minus: result *= -1

#
template useUnsafeOutput() =
  setStdIoUnbuffered()
  proc puts(str: untyped){.header: "<stdio.h>", varargs.}
  proc puts(str: cstring){.header: "<stdio.h>", varargs.}
  proc fputs(c: cstring, f: File) {.importc: "fputs", header: "<stdio.h>",tags: [WriteIOEffect].}
  template put(c:untyped) = fputs(cstring(c),stdout)
  proc funlockfile(f:File) {.importc: "funlockfile", header:"<stdio.h>" .}
  proc printf(formatstr: cstring){.header: "<stdio.h>", varargs.}
  proc putchar_unlocked(c:char){. importc:"putchar_unlocked",header: "<stdio.h>" .}
  proc printInt(a0:int32) =
    # if a0 < 0 : putchar_unlocked('-') # マイナスにも対応したければこれで可能
    # var a0 = a0.abs
    template div10(a:int32) : int32 = cast[int32]((0x1999999A * cast[int64](a)) shr 32)
    template put(n:int32) = putchar_unlocked("0123456789"[n])
    proc getPrintIntNimCode(n,maxA:static[int32]):string =
      result = "if a0 < " & $maxA & ":\n"
      for i in 1..n: result &= "  let a" & $i & " = a" & $(i-1) & ".div10\n"
      result &= "  put(a" & $n & ")\n"
      for i in n.countdown(1): result &= "  put(a" & $(i-1) & "-a" & $i & "*10)\n"
      result &= "  return"
    macro eval(s:static[string]): auto = parseStmt(s)
    eval(getPrintIntNimCode(0,10))
    eval(getPrintIntNimCode(1,100))
    eval(getPrintIntNimCode(2,1000))
    eval(getPrintIntNimCode(3,10000))
    eval(getPrintIntNimCode(4,100000))
    eval(getPrintIntNimCode(5,1000000))
    eval(getPrintIntNimCode(6,10000000))
    eval(getPrintIntNimCode(7,100000000))
    eval(getPrintIntNimCode(8,1000000000))
  template printInt(n:int,c:char) =
    printInt(n.int32)
    putchar_unlocked(c)

  proc printInt(a0:int) =
    # if a0 < 0 : putchar_unlocked('-') # マイナスにも対応したければこれで可能
    # var a0 = a0.abs
    template put(n:int) = putchar_unlocked("0123456789"[n])
    proc getPrintIntNimCode(n,maxA:static[int64]):string =
      result = "if a0 < " & $maxA & ":\n"
      for i in 1..n: result &= "  let a" & $i & " = a" & $(i-1) & " div 10\n"
      result &= "  put(a" & $n & ")\n"
      for i in n.countdown(1): result &= "  put(a" & $(i-1) & "-a" & $i & "*10)\n"
      result &= "  return"
    macro eval(s:static[string]): auto = parseStmt(s)
    eval(getPrintIntNimCode(0,10))
    eval(getPrintIntNimCode(1,100))
    eval(getPrintIntNimCode(2,1000))
    eval(getPrintIntNimCode(3,10000))
    eval(getPrintIntNimCode(4,100000))
    eval(getPrintIntNimCode(5,1000000))
    eval(getPrintIntNimCode(6,10000000))
    eval(getPrintIntNimCode(7,100000000))
    eval(getPrintIntNimCode(8,1000000000))
    eval(getPrintIntNimCode(9,10000000000))
    eval(getPrintIntNimCode(10,100000000000))
    eval(getPrintIntNimCode(11,1000000000000))
    eval(getPrintIntNimCode(12,10000000000000))
    eval(getPrintIntNimCode(13,100000000000000))
    eval(getPrintIntNimCode(14,1000000000000000))
    eval(getPrintIntNimCode(15,10000000000000000))
    eval(getPrintIntNimCode(16,100000000000000000))
    eval(getPrintIntNimCode(17,1000000000000000000))


# 整数位置管理用
template usePosition() =
  const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]
  const dxdy8 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0),(1,1),(1,-1),(-1,-1),(-1,1)]
  type Pos = tuple[x,y:int]
  proc `+`(p,v:Pos):Pos = (p.x+v.x,p.y+v.y)
  proc dot(p,v:Pos):int = p.x * v.x + p.y * v.y
0