結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-07-10 15:17:26 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,499 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 63,872 KB |
最終ジャッジ日時 | 2024-07-22 07:43:31 |
合計ジャッジ時間 | 6,881 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 2 TLE * 1 -- * 29 |
ソースコード
# -*- 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()