結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  かりあげクン | 
| 提出日時 | 2020-08-24 23:40:55 | 
| 言語 | Nim (2.2.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 502 bytes | 
| コンパイル時間 | 3,977 ms | 
| コンパイル使用メモリ | 65,836 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-01 09:54:02 | 
| 合計ジャッジ時間 | 5,106 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
import strutils
import sequtils
import heapqueue
import bitops
let N = stdin.readLine.parseInt
var dist = newSeqWith(N+1, 123456789)
var hq = initHeapQueue[(int, int)]()
hq.push((1, 1))
while hq.len != 0:
  let (c, v) = hq.pop
  if dist[v] <= c:
    continue
  dist[v] = c
  if v == N:
    echo c
    quit()
  let popcnt = popcount(v)
  for i in @[-1, 1]:
    if 0 < v + i * popcnt and v + i * popcnt <= N and dist[v] + 1 < dist[v + i * popcnt]:
      push(hq, ((dist[v] + 1), v + i * popcnt))
echo -1
            
            
            
        