結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
steek79
|
| 提出日時 | 2015-10-23 13:58:14 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 5,000 ms |
| コード長 | 488 bytes |
| 記録 | |
| コンパイル時間 | 130 ms |
| コンパイル使用メモリ | 77,588 KB |
| 最終ジャッジ日時 | 2025-12-03 17:41:47 |
|
ジャッジサーバーID (参考情報) |
judge3 / 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