結果

問題 No.3 ビットすごろく
ユーザー rocoder
提出日時 2017-08-04 06:07:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-07-01 08:47:21
合計ジャッジ時間 2,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

# your code goes here
def m(nu):
    bi=format (nu,'b')
    C=0
    for i in range (len (bi)):
        if bi[i]=="1":
            C+=1
        #    print("bi")
      #      print (nu)
    return C
N=int(input())
Nd=0
v=[0]*N
v[0]=1
t=[[1]]
i=0
while Nd<1:
    j=0
    t.append([])
    while j<len(t[i]):
        mt=m(t[i][j])+t[i][j]
    #    print (mt)
        if mt==N:
            Nd=1
        elif mt<N and mt>0:     
            if v[mt-1]==0:
         #       print (v)
                v[mt-1]=1
                t[i+1].append(mt)
        j+=1
    #    print (t[i])
    j-=len(t[i])
    while j<len(t[i]):
        mt=-1*m(t[i][j])+t[i][j]
        if mt==N:
            Nd=1
        elif mt<N and mt>0:
            if v[mt-1]==0:
                t[i+1].append(mt)
                v[mt-1]=1
        j+=1
   # print (t)
   # print (i)
    if Nd<1 and t[i+1]==[]:
        Nd=2
    i+=1
if N==1:
    p=1
elif Nd==1:
    p=len(t)
else:
    p=-1
print (p)
0