結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-13 12:51:44 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,840 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-10-07 20:49:45 |
| 合計ジャッジ時間 | 2,125 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 22 |
ソースコード
# -*- coding: utf-8 -*-
import sys
import math
import copy
def main():
text = sys.stdin.readline()
goal = int(text) #ゴール
ini_pos = 1 #初期値
ini_cost = 0
pos_cos = [ini_pos,ini_cost] #[position,cost]
costlist = [-1]*goal
exactlist = [False]*goal
costlist[0] = ini_cost
exactlist[0] = True
q = Que()
q.addQ(pos_cos)
#経路探索処理→ダイクストラ法、ゴールに到達した時点で終了
while not q.isEmpty():
pos_cos = q.popQ()
#行先判定処理
next_position_list = nextGoto(pos_cos[0])
for p in next_position_list:
if p == goal:
pos_cos[0] = p
pos_cos[1] += 1
exactlist[p-1] = True
costlist[p-1] = pos_cos[1]
print(costlist[goal-1])
return
elif p < 1 or p > goal:
continue
elif exactlist[p-1]:
continue
else:
pos_cos[0] = p
pos_cos[1] += 1
exactlist[p-1] = True
costlist[p-1] = pos_cos[1]
q.addQ(pos_cos)
print(-1)
return
class Que():
q_list = []
def lenQ(self):
return len(self.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)
move = len(binary_text.replace("0b","").replace("0",""))
goto = [arg_position - move, arg_position + move]
return goto
if __name__ == "__main__":
main()