結果

問題 No.3 ビットすごろく
ユーザー hosobikihosobiki
提出日時 2018-07-10 15:17:26
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,499 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 55,592 KB
最終ジャッジ日時 2023-09-29 13:24:46
合計ジャッジ時間 7,450 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 17 ms
8,532 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)    #ゴール
    start = 1           #初期値
    path_list = [start]
    q = Que()
    q.addQ(path_list)
    
    #経路探索処理→幅優先探索、ゴールに到達した時点で終了
    while not q.isEmpty():
        path_list = q.popQ()
        next_position_list = nextGoto(path_list[-1])
        for p in next_position_list:
            if p < 1 or p > goal:
                continue
            elif p in path_list:
                continue
            elif p == goal:
                path_list.append(p)
                #print(path_list,len(path_list)-1)
                print(len(path_list)-1)
                return
            else:
                buf_list = copy.deepcopy(path_list)
                buf_list.append(p)
                q.addQ(buf_list)
    print(-1)
    return


class Que():
    q_list = []
    def addQ(self,arg_pathlist):
        self.q_list.append(arg_pathlist)
        return
    def popQ(self):
        return self.q_list.pop(0)
    def isEmpty(self):
        if len(self.q_list) <= 0 :
            flag = True
        else:
            flag = False
        return flag

#行先返答関数
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