結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-04-17 18:32:36 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3,691 ms / 5,000 ms | 
| コード長 | 453 bytes | 
| コンパイル時間 | 88 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 11,136 KB | 
| 最終ジャッジ日時 | 2024-07-01 08:42:16 | 
| 合計ジャッジ時間 | 46,464 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
from collections import deque
def NX(a):
  global N,K
  K[a]=a
  r=[]
  b=bin(a).count("1")
  if 0 < a-b and not a-b in K:r.append(a-b)
  if N >= a+b and not a+b in K:r.append(a+b)
  return(r)
N=int(input())
G=-1 if N!=1 else 1
buf=deque()
buf.append([1,1])
if N==1:
  buf.clear()
K=[0]*(N+1)
while len(buf):
  c,n=buf.popleft()
  if n in K:continue
  for i in NX(n):
    if i==N:
      buf.clear()
      G=c+1
    buf.append([c+1,i])
    
print(G)
            
            
            
        