結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
steek79
|
| 提出日時 | 2015-10-23 14:04:22 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 5,000 ms |
| コード長 | 546 bytes |
| コンパイル時間 | 53 ms |
| コンパイル使用メモリ | 7,040 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-07-01 07:34:35 |
| 合計ジャッジ時間 | 1,615 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
N = input()
been = [-1] + [1] + [-1] * N
locations = deque()
locations.append(1)
while locations:
loc = locations.popleft()
width = bin(loc).count('1')
move_r, move_l = loc + width, loc-width
if move_r <= N:
if been[move_r] == -1:
been[move_r] = been[loc] + 1
locations.append(move_r)
if move_l >= 1 and been[move_l] == -1:
been[move_l] = been[loc] + 1
locations.append(move_l)
if been[N] != -1:
print been[N]
exit()
print -1
steek79