結果

問題 No.3 ビットすごろく
ユーザー hosobikihosobiki
提出日時 2018-07-12 09:44:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,149 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 11,852 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-10-25 07:32:44
合計ジャッジ時間 7,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# -*- coding: utf-8 -*-
import sys
import math
import copy

def main():
    text = sys.stdin.readline()
    goal = int(text)    #ゴール
    path = [1]          #経路記録用
    stack = [path]
    
    #経路探索処理→深さ優先探索、ゴールに到達した時点で終了
    while len(stack) > 0:
        path = stack.pop(-1)

        #行先判定処理
        next_position_list = nextGoto(path[-1])
        for p in next_position_list:
            if p == goal:
                path.append(p)
                #print(path,len(path))
                print(len(path))
                return
            elif p < 1 or p > goal:
                continue
            elif p in path:
                continue
            else:
                buf_path = copy.deepcopy(path)
                buf_path.append(p)
                stack.append(buf_path)
    print(-1)
    return



#行先返答関数
def nextGoto(arg_position):
    binary_text = bin(arg_position)
    steps = len(binary_text.replace("0b","").replace("0",""))
    goto = [arg_position - steps, arg_position + steps]
    return goto

if __name__ == "__main__":
    main()
0