結果

問題 No.3 ビットすごろく
ユーザー ゆるくゆるく
提出日時 2014-10-01 01:49:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 573 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 23,940 KB
最終ジャッジ日時 2023-08-28 19:59:59
合計ジャッジ時間 10,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,488 KB
testcase_01 AC 19 ms
8,480 KB
testcase_02 AC 19 ms
8,512 KB
testcase_03 AC 52 ms
8,688 KB
testcase_04 AC 24 ms
8,552 KB
testcase_05 AC 521 ms
9,488 KB
testcase_06 AC 56 ms
8,708 KB
testcase_07 AC 36 ms
8,648 KB
testcase_08 AC 193 ms
8,912 KB
testcase_09 AC 3,205 ms
14,696 KB
testcase_10 TLE -
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

N = int(input())


def bfs():
    v = deque([False] * (N + 1))
    q = deque()
    q.append([1,1])
    count = 0
    while(q):
        u = q.popleft()
        v[u[0]] = True
        bit1_count = '{:b}'.format(u[0]).count('1')
        v1 = u[0] + bit1_count
        v2 = u[0] - bit1_count
        if u[0] == N:
            return u[1]
        if (0 < v1 <= N) and not v[v1]:
            q.append([v1,u[1] + 1])
        if (0 < v2 <= N) and not v[v2]:
            q.append([v2, u[1] + 1])
    return -1

print(bfs())

0