結果

問題 No.3 ビットすごろく
ユーザー Mr.FukuMr.Fuku
提出日時 2018-06-24 21:34:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 510 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-09-13 13:47:23
合計ジャッジ時間 2,115 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,916 KB
testcase_01 AC 15 ms
7,768 KB
testcase_02 AC 15 ms
7,936 KB
testcase_03 AC 16 ms
8,184 KB
testcase_04 AC 15 ms
8,172 KB
testcase_05 AC 18 ms
8,352 KB
testcase_06 AC 17 ms
8,356 KB
testcase_07 AC 15 ms
8,204 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 18 ms
8,412 KB
testcase_13 AC 16 ms
8,264 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 15 ms
8,256 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 15 ms
7,768 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 15 ms
7,780 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 15 ms
7,752 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

n=int(input())

lst = [0]*(n+1)

def f(num,cnt):
    if num==n:
        print(cnt)
        return True
    
    step = str(bin(num))[2:].count("1")
    fowd_n = num+step
    back_n = num-step
    
    if fowd_n<=n and lst[fowd_n]==0:
        lst[fowd_n]=1
        if f(fowd_n,cnt+1):
            return True
    if back_n>0 and lst[back_n]==0:
        lst[back_n]=1
        if f(back_n,cnt+1):
            return True
    return False
lst[1]=1
if f(1,1)==False:
    print(-1)
0