結果

問題 No.3 ビットすごろく
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2021-07-04 11:49:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 76,948 KB
最終ジャッジ日時 2023-09-13 16:37:13
合計ジャッジ時間 4,703 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,464 KB
testcase_01 AC 69 ms
71,332 KB
testcase_02 AC 71 ms
71,256 KB
testcase_03 AC 82 ms
76,164 KB
testcase_04 AC 72 ms
71,388 KB
testcase_05 AC 87 ms
76,588 KB
testcase_06 AC 81 ms
76,564 KB
testcase_07 AC 79 ms
76,496 KB
testcase_08 AC 86 ms
76,744 KB
testcase_09 AC 86 ms
76,744 KB
testcase_10 AC 88 ms
76,816 KB
testcase_11 AC 87 ms
76,416 KB
testcase_12 AC 87 ms
76,496 KB
testcase_13 AC 81 ms
76,512 KB
testcase_14 AC 90 ms
76,608 KB
testcase_15 AC 89 ms
76,832 KB
testcase_16 AC 89 ms
76,736 KB
testcase_17 AC 89 ms
76,496 KB
testcase_18 AC 81 ms
76,704 KB
testcase_19 AC 90 ms
76,748 KB
testcase_20 AC 71 ms
71,340 KB
testcase_21 AC 71 ms
71,472 KB
testcase_22 AC 88 ms
76,616 KB
testcase_23 AC 88 ms
76,876 KB
testcase_24 AC 88 ms
76,948 KB
testcase_25 AC 88 ms
76,804 KB
testcase_26 AC 71 ms
71,104 KB
testcase_27 AC 81 ms
76,704 KB
testcase_28 AC 87 ms
76,604 KB
testcase_29 AC 86 ms
76,816 KB
testcase_30 AC 70 ms
71,284 KB
testcase_31 AC 71 ms
71,288 KB
testcase_32 AC 88 ms
76,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
went = []

l = [(1, 1)]
visited = {}
while(l):
    now, cost = l.pop(0)

    if now == N:
        print(cost)
        exit()

    bit_count = bin(now)[2:].count('1')
    forwarded = now + bit_count
    if forwarded <= N and not forwarded in visited:
        visited[forwarded] = True
        l.append((forwarded, cost + 1))

    backwarded = now - bit_count
    if 0 < backwarded and not backwarded in visited:
        visited[backwarded] = True
        l.append((backwarded, cost + 1))

print(-1)
0