結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-02-09 00:22:53 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 280 ms / 5,000 ms |
| コード長 | 547 bytes |
| 記録 | |
| コンパイル時間 | 128 ms |
| コンパイル使用メモリ | 77,496 KB |
| 最終ジャッジ日時 | 2025-12-03 13:35:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import math
from heapq import heappush, heappop
N = int(raw_input())
heap = []
heappush(heap,(1,1))
arrived = [False for i in range(N+1)]
while len(heap)>0:
dist, num = heappop(heap)
if arrived[num]:
continue
if num == N:
print dist
exit()
arrived[num]=True
tmp = num
cnt = 0
while tmp != 0:
tmp &= tmp-1
cnt+=1
if num-cnt > 0 and arrived[num-cnt] ==False:
heappush(heap,(dist+1,num-cnt))
if num+cnt <= N and arrived[num+cnt] ==False:
heappush(heap,(dist+1,num+cnt))
print -1
yaoshimax