結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-07-12 09:44:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,149 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 18,720 KB |
最終ジャッジ日時 | 2024-09-25 02:50:33 |
合計ジャッジ時間 | 6,839 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 1 -- * 29 |
ソースコード
# -*- 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()