結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-05 23:56:04 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 691 bytes |
| コンパイル時間 | 353 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 25,852 KB |
| 最終ジャッジ日時 | 2024-12-17 19:19:46 |
| 合計ジャッジ時間 | 112,760 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 1 TLE * 18 |
ソースコード
from collections import deque
import copy
import math
N = int(input())
if N == 1:
print(0)
else:
ans, already, que = 1, set(), deque([1])
while len(que) > 0:
nque = deque()
while len(que) > 0:
n = que.popleft()
already.add(n)
step = sum([(n >> i) % 2 for i in range((int(math.log2(n)) + 1))])
if n - step >= 1 and n - step not in already:
nque.append(n - step)
if n + step < N and n + step not in already:
nque.append(n + step)
elif n + step == N:
print(ans + 1)
exit()
que = copy.copy(nque)
ans += 1
print(-1)