結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
steek79
|
| 提出日時 | 2015-10-23 13:58:14 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 5,000 ms |
| コード長 | 488 bytes |
| コンパイル時間 | 69 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 6,656 KB |
| 最終ジャッジ日時 | 2024-07-01 07:34:34 |
| 合計ジャッジ時間 | 1,582 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
N = input()
been = [-1] + [1] + [-1] * N
locations = [1]
while locations:
loc = locations.pop(0)
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