結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
pro_kuni
|
| 提出日時 | 2019-10-13 21:37:30 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 97 ms / 5,000 ms |
| コード長 | 1,138 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-07-01 09:32:03 |
| 合計ジャッジ時間 | 3,204 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import sys, queue
class Walker():
def __init__(self, num):
self.num = num
def getNum(self):
return self.num
def getStep(self):
return self.step
def setStep(self, step):
self.step = step
def getMovility(self):
cnt = 0
bin_num = bin(self.num)[2:]
for i in bin_num:
if int(i):
cnt += 1
return cnt
n = int(input())
q = queue.Queue()
current = 1
movility = 1
step = 1
visited = [False for i in range(n)]
while True:
if current == n:
print(step)
break
if current - movility > 0 and not visited[current - movility - 1]:
w = Walker(current - movility)
w.setStep(step + 1)
q.put(w)
visited[current - movility - 1] = True
if current + movility <= n and not visited[current + movility - 1]:
w = Walker(current + movility)
w.setStep(step + 1)
q.put(w)
visited[current + movility - 1] = True
if q.empty():
print(-1)
break
w = q.get()
current = w.getNum()
step = w.getStep()
movility = w.getMovility()
pro_kuni