結果

問題 No.3 ビットすごろく
ユーザー lllllll88938494lllllll88938494
提出日時 2022-01-21 11:21:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 530 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,920 KB
最終ジャッジ日時 2023-08-16 15:43:48
合計ジャッジ時間 2,689 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,964 KB
testcase_01 AC 14 ms
7,816 KB
testcase_02 AC 14 ms
7,888 KB
testcase_03 AC 19 ms
8,300 KB
testcase_04 AC 15 ms
8,232 KB
testcase_05 AC 32 ms
8,512 KB
testcase_06 AC 20 ms
8,252 KB
testcase_07 AC 16 ms
8,192 KB
testcase_08 AC 28 ms
8,300 KB
testcase_09 AC 40 ms
8,616 KB
testcase_10 AC 57 ms
8,804 KB
testcase_11 AC 38 ms
8,652 KB
testcase_12 AC 31 ms
8,504 KB
testcase_13 AC 19 ms
8,212 KB
testcase_14 AC 56 ms
8,788 KB
testcase_15 AC 60 ms
8,888 KB
testcase_16 AC 59 ms
8,684 KB
testcase_17 AC 61 ms
8,744 KB
testcase_18 AC 18 ms
8,224 KB
testcase_19 AC 65 ms
8,904 KB
testcase_20 AC 15 ms
8,240 KB
testcase_21 AC 14 ms
7,748 KB
testcase_22 AC 54 ms
8,620 KB
testcase_23 AC 62 ms
8,720 KB
testcase_24 AC 63 ms
8,920 KB
testcase_25 AC 62 ms
8,876 KB
testcase_26 AC 14 ms
7,956 KB
testcase_27 AC 19 ms
8,396 KB
testcase_28 AC 58 ms
8,656 KB
testcase_29 AC 39 ms
8,548 KB
testcase_30 AC 14 ms
7,952 KB
testcase_31 AC 13 ms
7,820 KB
testcase_32 AC 35 ms
8,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

n=int(input())
ns=[]
for i in range(n):
    ns.append(str(bin(i+1)).count('1'))
inf=10**7
dist=[inf]*n
ans=[10**10]

def  dfs(x,cnt):
    dist[x] = cnt
    if x == n-1:
        ans[0] = min(ans[0],cnt)
        return
    
    if x+ns[x] < n:
        if dist[x+ns[x]] > cnt+1:
            dfs(x+ns[x],cnt+1)
            
    if x-ns[x] >= 0:
        if dist[x-ns[x]] > cnt+1:
            dfs(x-ns[x],cnt+1)
dfs(0,0)

if ans[0] == 10**10:
    print(-1)
else:
    print(ans[0]+1)
            
0