結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2016-07-16 10:01:03 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 24 ms / 5,000 ms |
コード長 | 351 bytes |
コンパイル時間 | 45 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-07-01 08:00:50 |
合計ジャッジ時間 | 1,625 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#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]