結果

問題 No.3 ビットすごろく
ユーザー kwnwsdnckwnwsdnc
提出日時 2018-03-30 03:41:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 888 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 9,460 KB
最終ジャッジ日時 2023-09-08 07:04:12
合計ジャッジ時間 2,100 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
9,320 KB
testcase_01 AC 21 ms
9,188 KB
testcase_02 AC 22 ms
9,272 KB
testcase_03 AC 23 ms
9,332 KB
testcase_04 AC 23 ms
9,368 KB
testcase_05 AC 23 ms
9,284 KB
testcase_06 AC 22 ms
9,296 KB
testcase_07 AC 21 ms
9,324 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 24 ms
9,284 KB
testcase_13 AC 22 ms
9,372 KB
testcase_14 AC 24 ms
9,252 KB
testcase_15 AC 26 ms
9,384 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 22 ms
9,228 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 20 ms
9,268 KB
testcase_22 AC 24 ms
9,424 KB
testcase_23 AC 27 ms
9,268 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 21 ms
9,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 22 ms
9,376 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def count(n):
    a=0
    num=str(bin(n))
    ln=len(num)
    for i in range(ln):
        if num[i]=='1':
            a+=1
    return a


def breadth(N):
    q=[[0 for i in range(2)]for j in range(10000)]
    mile=[0 for i in range(20000)]
    num=[0 for i in range(2)]
    q[0][0]=1
    mile[1]=1
    layer=1
    k=0
    j=0
    i=0
    while q!=None:
        if max(q[i])==0:
            return -1
        if N==1:
            return 1
        k=0
        j=0
        while layer>j:
            num[0]=q[i][j]+count(q[i][j])
            num[1]=q[i][j]-count(q[i][j])
            for n in num:
                if mile[n]==0 and n<=N:
                    q[i+1][k]=n
                    k+=1
                    mile[n]=1
                    if n==N:
                        return i+1+1
            j+=1
        layer=j    
        i+=1
        
        
N=int(input())
print(breadth(N))
0