結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2019-03-26 19:18:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 536 bytes |
コンパイル時間 | 127 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-10-11 01:34:36 |
合計ジャッジ時間 | 2,370 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 4 RE * 15 |
ソースコード
# -*- coding: utf-8 -*- INF = 1000000 n = int(input()) reached = [False] * (n+1) ans = INF def dfs(x,cnt): global ans if x < 1 or n < x: return if reached[x] == True: return if x == n: ans = min(ans, cnt) reached[x] = True go = bit_count(x) cnt += 1 dfs(x + go,cnt) dfs(x - go,cnt) def bit_count(x): tmp = str(bin(x)) one = 0 for i in tmp: if i == "1": one += 1 return one dfs(1,0) if ans != INF: print(ans+1) else: print(-1)