結果

問題 No.3 ビットすごろく
ユーザー setsunasetsuna
提出日時 2020-06-06 00:11:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 770 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2023-08-22 19:04:29
合計ジャッジ時間 3,065 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,800 KB
testcase_01 AC 21 ms
8,780 KB
testcase_02 AC 21 ms
8,780 KB
testcase_03 AC 29 ms
8,728 KB
testcase_04 AC 23 ms
8,888 KB
testcase_05 AC 39 ms
9,048 KB
testcase_06 AC 29 ms
8,860 KB
testcase_07 AC 26 ms
8,836 KB
testcase_08 AC 34 ms
8,904 KB
testcase_09 AC 45 ms
9,428 KB
testcase_10 AC 50 ms
9,632 KB
testcase_11 AC 42 ms
8,876 KB
testcase_12 AC 37 ms
9,008 KB
testcase_13 AC 28 ms
8,784 KB
testcase_14 AC 49 ms
9,432 KB
testcase_15 AC 55 ms
9,620 KB
testcase_16 AC 52 ms
9,564 KB
testcase_17 AC 56 ms
9,644 KB
testcase_18 AC 26 ms
8,872 KB
testcase_19 AC 56 ms
9,428 KB
testcase_20 AC 23 ms
8,744 KB
testcase_21 AC 22 ms
8,880 KB
testcase_22 AC 50 ms
9,636 KB
testcase_23 AC 56 ms
9,468 KB
testcase_24 AC 55 ms
9,604 KB
testcase_25 AC 53 ms
9,612 KB
testcase_26 WA -
testcase_27 AC 27 ms
8,824 KB
testcase_28 AC 51 ms
9,484 KB
testcase_29 AC 42 ms
9,520 KB
testcase_30 AC 21 ms
8,676 KB
testcase_31 AC 21 ms
8,736 KB
testcase_32 AC 41 ms
9,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import copy
import math

N = int(input())
if N == 1:
    print(0)
else:
    ans, already, que = 1, set([1]), deque([1])
    while len(que) > 0:
        nque = deque()
        while len(que) > 0:
            n = que.popleft()
            k, step = n, 0
            while k > 0:
                step += k % 2
                k >>= 1
            if n - step >= 1 and n - step not in already:
                nque.append(n - step)
                already.add(n - step)
            if n + step < N and n + step not in already:
                nque.append(n + step)
                already.add(n + step)
            elif n + step == N:
                print(ans + 1)
                exit()
        que = copy.copy(nque)
        ans += 1
print(-1)
0