結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2024-06-07 06:15:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 64 ms / 5,000 ms |
コード長 | 502 bytes |
コンパイル時間 | 367 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 63,488 KB |
最終ジャッジ日時 | 2024-12-25 05:58:36 |
合計ジャッジ時間 | 3,390 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import dequeN = int(input())todo = deque()todo.append(0)counts = [0] * Ncounts[0] = 1while len(todo) > 0:i = todo.popleft()if i == N - 1:print(counts[i])exit()back = i - (i + 1).bit_count()front = i + (i + 1).bit_count()if back >= 0 and counts[back] == 0:counts[back] = counts[i] + 1todo.append(back)if front < N and counts[front] == 0:counts[front] = counts[i] + 1todo.append(front)print(-1)