結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,704 KB
testcase_01 AC 19 ms
8,736 KB
testcase_02 AC 20 ms
8,828 KB
testcase_03 AC 27 ms
8,792 KB
testcase_04 AC 21 ms
8,880 KB
testcase_05 AC 35 ms
8,964 KB
testcase_06 AC 27 ms
8,984 KB
testcase_07 AC 26 ms
8,836 KB
testcase_08 AC 34 ms
9,140 KB
testcase_09 AC 43 ms
9,588 KB
testcase_10 AC 46 ms
9,620 KB
testcase_11 AC 40 ms
9,044 KB
testcase_12 AC 36 ms
8,976 KB
testcase_13 AC 25 ms
8,992 KB
testcase_14 AC 46 ms
9,444 KB
testcase_15 AC 53 ms
9,460 KB
testcase_16 AC 50 ms
9,440 KB
testcase_17 AC 55 ms
9,500 KB
testcase_18 AC 25 ms
8,972 KB
testcase_19 AC 53 ms
9,692 KB
testcase_20 AC 21 ms
8,724 KB
testcase_21 AC 19 ms
8,744 KB
testcase_22 AC 46 ms
9,524 KB
testcase_23 AC 53 ms
9,524 KB
testcase_24 AC 58 ms
9,572 KB
testcase_25 AC 53 ms
9,652 KB
testcase_26 WA -
testcase_27 AC 26 ms
8,808 KB
testcase_28 AC 51 ms
9,652 KB
testcase_29 AC 41 ms
9,596 KB
testcase_30 AC 19 ms
8,824 KB
testcase_31 AC 20 ms
8,808 KB
testcase_32 AC 39 ms
8,928 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