結果

問題 No.3 ビットすごろく
ユーザー dydy
提出日時 2020-10-24 21:53:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 684 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 209,204 KB
最終ジャッジ日時 2023-09-28 20:58:07
合計ジャッジ時間 18,527 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,896 KB
testcase_01 AC 99 ms
71,416 KB
testcase_02 AC 94 ms
71,588 KB
testcase_03 AC 136 ms
77,816 KB
testcase_04 AC 115 ms
77,540 KB
testcase_05 AC 311 ms
81,448 KB
testcase_06 AC 133 ms
77,844 KB
testcase_07 AC 123 ms
77,700 KB
testcase_08 AC 187 ms
78,768 KB
testcase_09 AC 1,398 ms
116,516 KB
testcase_10 AC 3,625 ms
209,204 KB
testcase_11 AC 895 ms
99,660 KB
testcase_12 AC 273 ms
80,892 KB
testcase_13 AC 128 ms
77,916 KB
testcase_14 AC 3,032 ms
183,192 KB
testcase_15 TLE -
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())

steps = [None, 1]
visited = [None, False]
for _ in range(2, n+1):
    steps.append(-1)
    visited.append(False)

q = deque([])
start = 1
q.append(start)
while q:
    v = q.popleft()
    visited[v] = True
    if v == n:
        # print("goal")
        break
    num = bin(v).count('1')
    for next_v in [v + num, v - num]:
        if 1 <= next_v and next_v <= n:
            if visited[next_v] == False:
                q.append(next_v)
                if steps[next_v] == -1:
                    steps[next_v] = steps[v] + 1
                else:
                    steps[next_v] = min(steps[next_v], steps[v] + 1)

print(steps[n])
0