結果

問題 No.3 ビットすごろく
ユーザー setsunasetsuna
提出日時 2020-06-06 00:12:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 774 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 9,712 KB
最終ジャッジ日時 2023-09-14 01:45:20
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,740 KB
testcase_01 AC 23 ms
8,740 KB
testcase_02 AC 21 ms
8,844 KB
testcase_03 AC 29 ms
8,856 KB
testcase_04 AC 23 ms
8,832 KB
testcase_05 AC 39 ms
8,996 KB
testcase_06 AC 29 ms
8,884 KB
testcase_07 AC 26 ms
8,916 KB
testcase_08 AC 35 ms
8,976 KB
testcase_09 AC 45 ms
9,520 KB
testcase_10 AC 49 ms
9,488 KB
testcase_11 AC 42 ms
9,140 KB
testcase_12 AC 37 ms
8,960 KB
testcase_13 AC 27 ms
8,804 KB
testcase_14 AC 48 ms
9,600 KB
testcase_15 AC 56 ms
9,496 KB
testcase_16 AC 52 ms
9,532 KB
testcase_17 AC 54 ms
9,712 KB
testcase_18 AC 27 ms
9,000 KB
testcase_19 AC 54 ms
9,672 KB
testcase_20 AC 22 ms
8,776 KB
testcase_21 AC 21 ms
8,728 KB
testcase_22 AC 48 ms
9,624 KB
testcase_23 AC 56 ms
9,496 KB
testcase_24 AC 55 ms
9,676 KB
testcase_25 AC 55 ms
9,628 KB
testcase_26 AC 21 ms
8,856 KB
testcase_27 AC 28 ms
8,916 KB
testcase_28 AC 52 ms
9,680 KB
testcase_29 AC 43 ms
9,660 KB
testcase_30 AC 21 ms
8,748 KB
testcase_31 AC 21 ms
8,840 KB
testcase_32 AC 40 ms
9,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import copy
import math

N = int(input())
if N == 1:
    print(1)
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