結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,268 KB
testcase_01 AC 23 ms
9,276 KB
testcase_02 AC 22 ms
9,324 KB
testcase_03 AC 24 ms
9,360 KB
testcase_04 AC 23 ms
9,280 KB
testcase_05 AC 26 ms
9,252 KB
testcase_06 AC 24 ms
9,304 KB
testcase_07 AC 23 ms
9,324 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 26 ms
9,320 KB
testcase_13 AC 24 ms
9,348 KB
testcase_14 AC 27 ms
9,388 KB
testcase_15 AC 28 ms
9,280 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 24 ms
9,212 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 22 ms
9,240 KB
testcase_22 AC 26 ms
9,348 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 AC 21 ms
9,300 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 21 ms
9,272 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(10000)]
    num=[0 for i in range(2)]
    v=1
    q[0][0]=v
    mile[v]=1
    h=1
    k=0
    j=0
    i=0
    while q!=None:
        if max(q[i])==0:
            return -1
        if N==1:
            return 1
        
        while h>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
            
        h=j
        i+=1
        j=0
        k=0
        
        
    
    
N=int(input())
print(breadth(N))
0