結果

問題 No.3 ビットすごろく
ユーザー setsunasetsuna
提出日時 2020-06-05 23:56:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 691 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 19,724 KB
最終ジャッジ日時 2023-08-22 18:35:00
合計ジャッジ時間 8,445 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
19,724 KB
testcase_01 AC 21 ms
8,896 KB
testcase_02 AC 21 ms
8,868 KB
testcase_03 AC 861 ms
9,400 KB
testcase_04 AC 138 ms
9,076 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0