結果

問題 No.3 ビットすごろく
コンテスト
ユーザー yaoshimax
提出日時 2015-02-09 00:22:53
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 140 ms / 5,000 ms
+ 22µs
コード長 547 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 69 ms
コンパイル使用メモリ 80,896 KB
実行使用メモリ 85,308 KB
最終ジャッジ日時 2026-07-17 09:10:30
合計ジャッジ時間 5,395 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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
0