結果

問題 No.3 ビットすごろく
ユーザー ぺ鳥ぺ鳥
提出日時 2022-06-13 12:30:56
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 693 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 11,808 KB
実行使用メモリ 10,436 KB
最終ジャッジ日時 2023-10-25 21:35:15
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,096 KB
testcase_01 AC 28 ms
10,096 KB
testcase_02 AC 27 ms
10,096 KB
testcase_03 AC 30 ms
10,144 KB
testcase_04 AC 28 ms
10,096 KB
testcase_05 AC 35 ms
10,248 KB
testcase_06 AC 31 ms
10,148 KB
testcase_07 AC 28 ms
10,112 KB
testcase_08 AC 36 ms
10,208 KB
testcase_09 AC 38 ms
10,316 KB
testcase_10 AC 40 ms
10,368 KB
testcase_11 AC 37 ms
10,288 KB
testcase_12 AC 34 ms
10,248 KB
testcase_13 AC 29 ms
10,128 KB
testcase_14 AC 39 ms
10,360 KB
testcase_15 AC 42 ms
10,420 KB
testcase_16 AC 41 ms
10,404 KB
testcase_17 AC 42 ms
10,420 KB
testcase_18 AC 29 ms
10,124 KB
testcase_19 AC 43 ms
10,424 KB
testcase_20 AC 28 ms
10,096 KB
testcase_21 AC 27 ms
10,096 KB
testcase_22 AC 39 ms
10,360 KB
testcase_23 AC 43 ms
10,424 KB
testcase_24 AC 43 ms
10,424 KB
testcase_25 AC 43 ms
10,436 KB
testcase_26 WA -
testcase_27 AC 30 ms
10,140 KB
testcase_28 AC 42 ms
10,400 KB
testcase_29 AC 36 ms
10,296 KB
testcase_30 AC 28 ms
10,096 KB
testcase_31 AC 27 ms
10,096 KB
testcase_32 AC 36 ms
10,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())

v = deque([0] * N)
q = deque()
q.append(1)
v[0] = 1


result = False

if N == 1:
    print(0)
else:
    while(q):
        bin_count = bin(int(q[0])).count('1')
        v_next = q[0] + bin_count
        v_back = q[0] - bin_count
        if v_next <= N and v[v_next - 1] == 0:
            v[v_next - 1] = v[q[0] - 1] + 1
            q.append(v_next)
            if v_next == N:
                print(v[N -1])
                result = True
                break
        if 0 < v_back <= N and v[v_back - 1] == 0:
            v[v_back - 1] = v[q[0] - 1] + 1
            q.append(v_back)
        q.popleft()


if result != True:
    print(-1)
    

0