結果

問題 No.3 ビットすごろく
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-02-09 01:16:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 732 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 12,920 KB
最終ジャッジ日時 2023-09-14 04:04:45
合計ジャッジ時間 17,604 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,036 KB
testcase_01 AC 16 ms
7,848 KB
testcase_02 AC 16 ms
7,828 KB
testcase_03 AC 965 ms
7,840 KB
testcase_04 AC 96 ms
7,808 KB
testcase_05 AC 4,768 ms
8,232 KB
testcase_06 AC 1,172 ms
7,820 KB
testcase_07 AC 402 ms
7,764 KB
testcase_08 AC 3,000 ms
8,400 KB
testcase_09 TLE -
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:
# for i in range(1,N+1):
    i = stack.pop()
    cnt = bin(i).count("1")
    if 1 <= i+cnt  <= N:
        if dp[i]+1 < dp[i+cnt] :
            stack.append( i+cnt )
            dp[i+cnt] = dp[i]+1
    if 1 <= i-cnt  <= N:
        if dp[i]+1 < dp[i-cnt] :
            stack.append( i-cnt )
            dp[i-cnt] = dp[i]+1
        # dp[i-cnt] = min(dp[i-cnt], dp[i]+1)

    # for j in range(1, cnt+1):
    #     try:
    #         dp[i+j] = min(dp[i+j], dp[i]+1)
    #     except IndexError:
    #         continue
    # 
print(dp[N] if dp[N] != 10**9 else -1)
# print(dp)
0