結果

問題 No.3 ビットすごろく
ユーザー tachyon777tachyon777
提出日時 2020-02-13 12:49:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 537 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 80,212 KB
最終ジャッジ日時 2024-04-15 15:59:50
合計ジャッジ時間 5,709 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
80,080 KB
testcase_01 AC 112 ms
79,824 KB
testcase_02 AC 112 ms
80,080 KB
testcase_03 AC 130 ms
79,700 KB
testcase_04 WA -
testcase_05 AC 128 ms
79,956 KB
testcase_06 AC 123 ms
79,692 KB
testcase_07 AC 121 ms
79,696 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 129 ms
79,824 KB
testcase_13 AC 119 ms
79,692 KB
testcase_14 AC 138 ms
79,868 KB
testcase_15 AC 147 ms
80,204 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 122 ms
79,824 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 109 ms
79,956 KB
testcase_22 AC 129 ms
79,700 KB
testcase_23 AC 144 ms
80,212 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 137 ms
79,956 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 111 ms
79,820 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
lst1 = []
for i in range(1,100001):
    dig = len(bin(i))-2
    res = 0
    for j in range(dig):
        if i >> j & 1:
            res += 1
    lst1.append(res)

visited = [0]*(n+1)
ret = 10**9
def bfs(now,ans):
    global ret
    if now == n-1:
        ret = min(ret,ans)
        return
    if now > n or now < 0:
        return
    if visited[now] == 1:
        return
    visited[now] = 1
    bfs(now+lst1[now],ans+1)
    bfs(now-lst1[now],ans+1)
    return ret if ret < 10**9 else -1
    
print(bfs(0,1))
    
    
0