結果

問題 No.3 ビットすごろく
ユーザー jamadjamad
提出日時 2017-08-11 06:17:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 880 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-20 21:52:49
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 33 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 89 ms
11,136 KB
testcase_04 AC 31 ms
10,624 KB
testcase_05 AC 296 ms
11,264 KB
testcase_06 AC 104 ms
11,008 KB
testcase_07 AC 35 ms
10,752 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 283 ms
11,264 KB
testcase_13 AC 71 ms
11,008 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 33 ms
10,880 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 31 ms
10,752 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 31 ms
10,752 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def go(target,current,path):
    if current==target:
#        print('DONE!')
        return
#    print('debug',current, Z)
    x=bin(current)[2:].count('1')
    f,b=current+x,current-x
    if 0<f<=N or 0<b<=N:
        if f in Z and b in Z:
            return
        else:
            if 0<f<=N and f not in Z:
                Z.add(f)
                path.append(f)
                go(N,f,path)
                R.append(path)
                if path[-1]==target:return
            if 0<b<=N and b not in Z:
                Z.add(b)
                path.append(b)
                go(N,b,path)
                R.append(path)
                if path[-1]==target:return
    else:
        return

#    f,b=current
    return
    
N=int(input())
A=[x for x in range(1,N+1)]
Z={1}
current=1
path=[1]
R=[]
go(N,current,path)
#print(Z,R)
print(min([len(r) if N in r else -1 for r in R ]))
0