結果

問題 No.3 ビットすごろく
ユーザー MakorominirisMakorominiris
提出日時 2016-05-26 08:32:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 329 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-01 07:55:46
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
a=[0]*(N+1)
a[1]=1
ne=[1]
cnt=1
while(True):
  if N in ne:break
  tmp=[]
  for v in ne:
    d=bin(v).count("1")
    if v-d>0 and a[v-d]!=1:
      tmp.insert(0,v-d)
      a[v-d]=1
    if v+d<=N and a[v+d]!=1:
      tmp.insert(0,v+d)
      a[v+d]=1
  if len(tmp)==0:
    cnt=-1
    break
  cnt+=1
  ne=tmp
print(cnt)
0