結果

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

コンパイルメッセージ
/home/judge/data/code/Main.nim(5, 7) Error: undeclared identifier: 'lc'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 0): 'n' [let declared in /home/judge/data/code/Main.nim(3, 5)]
 (2, 2): '!=' [template declared in /nim-1.6.12/lib/system/comparisons.nim(128, 10)]
 (2, 2): '$' [func declared in /nim-1.6.12/lib/system/dollars.nim(25, 8)]
 (2, 2): '$' [func declared in /nim-1.6.12/lib/system/dollars.nim(25, 8)]

ソースコード

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