結果

問題 No.3 ビットすごろく
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-02-09 01:18:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 580 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2023-09-14 04:03:57
合計ジャッジ時間 8,648 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,964 KB
testcase_01 AC 15 ms
7,768 KB
testcase_02 AC 15 ms
7,844 KB
testcase_03 AC 1,584 ms
7,948 KB
testcase_04 AC 111 ms
7,784 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
dp = [10**9 for _ in range(N+1)]

dp[1] = 1
stack = [1]
while stack:
    i = stack.pop()
    cnt = bin(i).count("1")
    if 1 <= i+cnt  <= N:
        if dp[i]+1 < dp[i+cnt] :
            if not (i+cnt) in stack:
                stack.append( i+cnt )
            dp[i+cnt] = dp[i]+1

    if 1 <=  i-cnt  <= N:
        if dp[i]+1 < dp[i-cnt] :
            if not (i-cnt) in stack:
                stack.append( i-cnt )
            dp[i-cnt] = dp[i]+1
print(dp[N] if dp[N] != 10**9 else -1)
0