結果

問題 No.3 ビットすごろく
ユーザー apahieapahie
提出日時 2019-04-21 22:58:56
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 547 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 66,584 KB
最終ジャッジ日時 2024-04-27 02:51:43
合計ジャッジ時間 1,274 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(5, 7) Error: undeclared identifier: 'lc'

ソースコード

diff #

import sequtils, strutils,sugar, deques

let n = stdin.readLine.parseInt
var
  l = lc[high(int) | (_ <- 0..<n), int]
  q = initDeque[int]()
l[0] = 1
q.addLast 1

proc bfs(): int =
  while q.len != 0:
    let
      now = q.popFirst
      cnt = l[now-1]+1
    for sign in @[-1, 1]:
      let
        move = sign * ($now).parseBiggestInt.toBin(16).count('1')
        ni = now + move
      if ni == n:
        return cnt

      if ni in 1..n and l[ni-1] == high(int):
        l[ni-1] = cnt
        q.addLast ni
  return -1

echo if n==1: 1 else: bfs()
0