結果

問題 No.3 ビットすごろく
ユーザー rocoderrocoder
提出日時 2017-08-04 06:07:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,796 KB
最終ジャッジ日時 2023-09-14 00:47:18
合計ジャッジ時間 2,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,272 KB
testcase_01 AC 16 ms
8,228 KB
testcase_02 AC 15 ms
8,208 KB
testcase_03 AC 23 ms
8,480 KB
testcase_04 AC 18 ms
8,192 KB
testcase_05 AC 36 ms
8,432 KB
testcase_06 AC 25 ms
8,360 KB
testcase_07 AC 21 ms
8,428 KB
testcase_08 AC 29 ms
8,340 KB
testcase_09 AC 41 ms
8,576 KB
testcase_10 AC 45 ms
8,596 KB
testcase_11 AC 39 ms
8,520 KB
testcase_12 AC 36 ms
8,572 KB
testcase_13 AC 23 ms
8,364 KB
testcase_14 AC 45 ms
8,624 KB
testcase_15 AC 53 ms
8,604 KB
testcase_16 AC 50 ms
8,628 KB
testcase_17 AC 52 ms
8,668 KB
testcase_18 AC 21 ms
8,276 KB
testcase_19 AC 53 ms
8,676 KB
testcase_20 AC 17 ms
8,204 KB
testcase_21 AC 16 ms
8,240 KB
testcase_22 AC 46 ms
8,604 KB
testcase_23 AC 51 ms
8,608 KB
testcase_24 AC 52 ms
8,608 KB
testcase_25 AC 51 ms
8,796 KB
testcase_26 AC 15 ms
8,272 KB
testcase_27 AC 22 ms
8,372 KB
testcase_28 AC 46 ms
8,756 KB
testcase_29 AC 39 ms
8,648 KB
testcase_30 AC 15 ms
8,320 KB
testcase_31 AC 16 ms
8,268 KB
testcase_32 AC 37 ms
8,520 KB
権限があれば一括ダウンロードができます

ソースコード

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