結果

問題 No.3 ビットすごろく
ユーザー AT274_AT274_
提出日時 2019-10-28 18:53:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 433 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 76,652 KB
最終ジャッジ日時 2023-10-12 23:07:24
合計ジャッジ時間 4,521 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,084 KB
testcase_01 AC 72 ms
71,044 KB
testcase_02 AC 73 ms
71,308 KB
testcase_03 AC 89 ms
76,092 KB
testcase_04 WA -
testcase_05 AC 88 ms
76,128 KB
testcase_06 AC 88 ms
76,396 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 92 ms
76,468 KB
testcase_13 AC 86 ms
76,104 KB
testcase_14 AC 92 ms
76,496 KB
testcase_15 AC 94 ms
76,260 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 75 ms
71,096 KB
testcase_22 AC 92 ms
76,352 KB
testcase_23 AC 93 ms
76,448 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 74 ms
71,112 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
dp = [0] * (N + 1)
visited = [False] * (N + 1)
stack = [[1, 1]]

while stack:
    n, cost = stack.pop()
    dp[n] = cost
    visited[n] = True

    move = bin(n)[2:].count('1')
    if n + move <= N:
        if not visited[n + move]:
            stack.append([n + move, cost + 1])

    if n - move > 0:
        if not visited[n - move]:
            stack.append([n - move, cost + 1])


print(dp[N] if dp[N] else - 1)
0