結果

問題 No.3 ビットすごろく
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-09 00:22:53
言語 Python2
(2.7.18)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 547 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 6,596 KB
実行使用メモリ 6,672 KB
最終ジャッジ日時 2023-09-13 23:00:50
合計ジャッジ時間 2,426 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,160 KB
testcase_01 AC 12 ms
6,256 KB
testcase_02 AC 12 ms
6,092 KB
testcase_03 AC 17 ms
6,232 KB
testcase_04 AC 13 ms
6,188 KB
testcase_05 AC 23 ms
6,356 KB
testcase_06 AC 17 ms
6,240 KB
testcase_07 AC 15 ms
6,244 KB
testcase_08 AC 21 ms
6,320 KB
testcase_09 AC 27 ms
6,488 KB
testcase_10 AC 29 ms
6,516 KB
testcase_11 AC 25 ms
6,468 KB
testcase_12 AC 22 ms
6,512 KB
testcase_13 AC 16 ms
6,376 KB
testcase_14 AC 28 ms
6,524 KB
testcase_15 AC 34 ms
6,672 KB
testcase_16 AC 31 ms
6,436 KB
testcase_17 AC 32 ms
6,608 KB
testcase_18 AC 15 ms
6,212 KB
testcase_19 AC 33 ms
6,612 KB
testcase_20 AC 13 ms
6,092 KB
testcase_21 AC 12 ms
6,096 KB
testcase_22 AC 28 ms
6,388 KB
testcase_23 AC 33 ms
6,664 KB
testcase_24 AC 33 ms
6,552 KB
testcase_25 AC 32 ms
6,580 KB
testcase_26 AC 12 ms
6,208 KB
testcase_27 AC 16 ms
6,284 KB
testcase_28 AC 31 ms
6,560 KB
testcase_29 AC 25 ms
6,396 KB
testcase_30 AC 13 ms
6,164 KB
testcase_31 AC 13 ms
6,156 KB
testcase_32 AC 24 ms
6,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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