結果

問題 No.3 ビットすごろく
ユーザー pluto77pluto77
提出日時 2016-07-16 10:01:03
言語 Python2
(2.7.18)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 351 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 6,628 KB
実行使用メモリ 6,604 KB
最終ジャッジ日時 2023-09-14 00:03:13
合計ジャッジ時間 2,734 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,284 KB
testcase_01 AC 13 ms
6,240 KB
testcase_02 AC 13 ms
6,212 KB
testcase_03 AC 15 ms
6,216 KB
testcase_04 AC 14 ms
6,368 KB
testcase_05 AC 19 ms
6,288 KB
testcase_06 AC 16 ms
6,328 KB
testcase_07 AC 14 ms
6,192 KB
testcase_08 AC 18 ms
6,432 KB
testcase_09 AC 20 ms
6,392 KB
testcase_10 AC 21 ms
6,480 KB
testcase_11 AC 19 ms
6,488 KB
testcase_12 AC 18 ms
6,388 KB
testcase_13 AC 15 ms
6,376 KB
testcase_14 AC 21 ms
6,556 KB
testcase_15 AC 23 ms
6,508 KB
testcase_16 AC 23 ms
6,448 KB
testcase_17 AC 23 ms
6,464 KB
testcase_18 AC 14 ms
6,300 KB
testcase_19 AC 23 ms
6,528 KB
testcase_20 AC 13 ms
6,248 KB
testcase_21 AC 13 ms
6,340 KB
testcase_22 AC 21 ms
6,456 KB
testcase_23 AC 23 ms
6,432 KB
testcase_24 AC 23 ms
6,604 KB
testcase_25 AC 23 ms
6,416 KB
testcase_26 AC 13 ms
6,284 KB
testcase_27 AC 16 ms
6,304 KB
testcase_28 AC 22 ms
6,444 KB
testcase_29 AC 20 ms
6,324 KB
testcase_30 AC 13 ms
6,344 KB
testcase_31 AC 13 ms
6,200 KB
testcase_32 AC 19 ms
6,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
#yuki_3
from collections import deque

n=int(raw_input())
d=[0 for i in xrange(n+1)]
d[1]=1
q=deque()
q.append(1)
while q:
 u=q.popleft()
 cnt=bin(u).count('1')
 v1=u+cnt
 v2=u-cnt
 if 0<v1<=n and d[v1]==0:
  q.append(v1)
  d[v1]=d[u]+1
 if 0<v2<=n and d[v2]==0:
  q.append(v2)
  d[v2]=d[u]+1
  
if d[n]==0:
 print -1
else:
 print d[n]
0