結果

問題 No.3 ビットすごろく
ユーザー ronpooronpoo
提出日時 2023-08-22 16:11:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 365 ms / 5,000 ms
コード長 432 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 161,684 KB
最終ジャッジ日時 2023-08-22 16:11:59
合計ジャッジ時間 8,662 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,264 KB
testcase_01 AC 74 ms
70,908 KB
testcase_02 AC 77 ms
71,272 KB
testcase_03 AC 139 ms
81,564 KB
testcase_04 AC 95 ms
76,320 KB
testcase_05 AC 212 ms
109,516 KB
testcase_06 AC 142 ms
79,452 KB
testcase_07 AC 119 ms
78,848 KB
testcase_08 AC 193 ms
98,788 KB
testcase_09 AC 258 ms
124,264 KB
testcase_10 AC 324 ms
135,652 KB
testcase_11 AC 253 ms
121,312 KB
testcase_12 AC 220 ms
110,956 KB
testcase_13 AC 136 ms
80,980 KB
testcase_14 AC 323 ms
143,816 KB
testcase_15 AC 365 ms
161,684 KB
testcase_16 AC 291 ms
115,328 KB
testcase_17 AC 363 ms
151,736 KB
testcase_18 AC 127 ms
78,664 KB
testcase_19 AC 355 ms
154,236 KB
testcase_20 AC 89 ms
76,596 KB
testcase_21 AC 74 ms
71,280 KB
testcase_22 AC 192 ms
85,112 KB
testcase_23 AC 291 ms
120,072 KB
testcase_24 AC 362 ms
155,836 KB
testcase_25 AC 350 ms
151,256 KB
testcase_26 AC 75 ms
71,324 KB
testcase_27 AC 144 ms
79,824 KB
testcase_28 AC 152 ms
79,616 KB
testcase_29 AC 269 ms
121,524 KB
testcase_30 AC 74 ms
71,360 KB
testcase_31 AC 75 ms
70,916 KB
testcase_32 AC 267 ms
123,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

N = int(input())

dist = [float('inf')] * (N+1)
dist[1] = 1

def dfs(now):
    v = str(format(now, 'b')).count('1')
    for x in [1, -1]:
        nxt = now + v*x
        if 1 < nxt <= N:
            if dist[nxt] > dist[now] + 1:
                dist[nxt] = dist[now] + 1
                dfs(nxt)        
    
dfs(1)

if dist[N] < float('inf'):
    ans = dist[N]
else:
    ans = -1
print(ans)
0