結果

問題 No.3 ビットすごろく
ユーザー jamad
提出日時 2017-08-13 05:27:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 234 ms / 5,000 ms
コード長 241 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 63,616 KB
最終ジャッジ日時 2024-07-01 08:47:37
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

def upd(x,t):
 if 0<x<=N and A[x]==[]:Q.append(x);A[x]=A[t]+[x]
    
def bfs():
 while Q:
  t=Q.pop(0)
  if t==N:return len(A[N])
  c=bin(t).count('1');upd(t+c,t);upd(t-c,t)
 return -1

N=int(input())
A=[[]]*10001
A[1]=[1]
Q=[1]
print(bfs())
0