結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2020-06-01 08:25:23 |
言語 | Nim (2.2.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,485 bytes |
コンパイル時間 | 1,066 ms |
コンパイル使用メモリ | 72,424 KB |
最終ジャッジ日時 | 2024-11-15 04:50:27 |
合計ジャッジ時間 | 1,548 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated] /home/judge/data/code/Main.nim(37, 18) Error: undeclared identifier: 'shallowCopy'
ソースコード
import sequtils,strutils,strscans,algorithm,math,future,sets,tables,bitopstypeQueue* [T] = object ## A queue.data: seq[T]rd, wr, count, mask: intproc initQueue*[T](initialSize: int = 4): Queue[T] =assert isPowerOfTwo(initialSize)result.mask = initialSize-1newSeq(result.data, initialSize)proc len*[T](q: Queue[T]): int {.inline.}= result = q.countproc front*[T](q: Queue[T]): T {.inline.}=result = q.data[q.rd]proc back*[T](q: Queue[T]): T {.inline.} =result = q.data[q.wr - 1 and q.mask]proc `[]`*[T](q: Queue[T], i: Natural) : T {.inline.} =return q.data[q.rd + i and q.mask]proc `[]`*[T](q: var Queue[T], i: Natural): var T {.inline.} =return q.data[q.rd + i and q.mask]proc `[]=`* [T] (q: var Queue[T], i: Natural, val : T) {.inline.} =q.data[q.rd + i and q.mask] = valiterator items*[T](q: Queue[T]): T =var i = q.rdfor c in 0 ..< q.count:yield q.data[i]i = (i + 1) and q.maskiterator pairs*[T](q: Queue[T]): tuple[key: int, val: T] =var i = q.rdfor c in 0 ..< q.count:yield (c, q.data[i])i = (i + 1) and q.maskproc add*[T](q: var Queue[T], item: T) =var cap = q.mask+1if unlikely(q.count >= cap):var n = newSeq[T](cap*2)for i, x in pairs(q): # don't use copyMem because the GC and because it's slower.shallowCopy(n[i], x)shallowCopy(q.data, n)q.mask = cap*2 - 1q.wr = q.countq.rd = 0inc q.countq.data[q.wr] = itemq.wr = (q.wr + 1) and q.masktemplate default[T](t: typedesc[T]): T =var v: Tvproc pop*[T](q: var Queue[T]): T {.inline, discardable.} =dec q.countresult = q.data[q.rd]q.data[q.rd] = default(type(result))q.rd = (q.rd + 1) and q.maskproc enqueue*[T](q: var Queue[T], item: T) = q.add(item)proc dequeue*[T](q: var Queue[T]): T = q.pop()proc `$`*[T](q: Queue[T]): string =result = "["for x in items(q): # Don't remove the items here for reasons that don't fit in this margin.if result.len > 1: result.add(", ")result.add($x)result.add("]")let n = stdin.readLine().parseIntvar open = initQueue[int]()var close = newSeqWith(n+1,-1)var resdepth = 0open.add(1)close[1] = 1while open.len > 0:let now = open.pop()let depth = close[now]if now == n:echo depthquit(0)let diff = countSetBits(now.int32)for succ in @[now + diff,now - diff]:if succ > n or succ < 1: continueif close[succ] == -1:close[succ] = depth + 1open.enqueue(succ)echo -1