結果

問題 No.3 ビットすごろく
ユーザー ic-eguciic-eguci
提出日時 2019-02-01 13:22:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 687 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,540 KB
最終ジャッジ日時 2023-09-14 01:11:27
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,780 KB
testcase_01 AC 16 ms
7,804 KB
testcase_02 AC 15 ms
7,764 KB
testcase_03 AC 19 ms
7,804 KB
testcase_04 AC 16 ms
7,852 KB
testcase_05 AC 24 ms
8,368 KB
testcase_06 AC 20 ms
7,780 KB
testcase_07 AC 17 ms
7,808 KB
testcase_08 AC 23 ms
8,240 KB
testcase_09 AC 28 ms
8,368 KB
testcase_10 AC 30 ms
8,416 KB
testcase_11 AC 26 ms
8,300 KB
testcase_12 AC 24 ms
8,248 KB
testcase_13 AC 19 ms
7,908 KB
testcase_14 AC 29 ms
8,404 KB
testcase_15 AC 34 ms
8,420 KB
testcase_16 AC 31 ms
8,528 KB
testcase_17 AC 33 ms
8,444 KB
testcase_18 AC 17 ms
7,896 KB
testcase_19 AC 34 ms
8,540 KB
testcase_20 AC 16 ms
7,788 KB
testcase_21 WA -
testcase_22 AC 30 ms
8,356 KB
testcase_23 AC 33 ms
8,536 KB
testcase_24 AC 34 ms
8,536 KB
testcase_25 AC 32 ms
8,452 KB
testcase_26 AC 15 ms
7,780 KB
testcase_27 AC 19 ms
7,768 KB
testcase_28 AC 32 ms
8,488 KB
testcase_29 AC 26 ms
8,344 KB
testcase_30 AC 15 ms
7,764 KB
testcase_31 AC 16 ms
7,784 KB
testcase_32 AC 26 ms
8,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def foo(N):
    distance = [bin(_).count('1') for _ in range(N+1)]
    shortest = [N for _ in range(N+1)]
    shortest[1] = 1
    changed = True
    while changed:
        changed = False
        for masu in range(1, N+1):
            dest = masu+distance[masu]
            if dest <= N:
                if shortest[masu]+1 < shortest[dest]:
                    shortest[dest] = shortest[masu]+1
                    changed = True
            dest = masu-distance[masu]
            if dest >= 1:
                if shortest[masu]+1 < shortest[dest]:
                    shortest[dest] = shortest[masu]+1
    return -1 if N!=1 and shortest[N]==N else shortest[N]
print(foo(int(input())))
0