結果

問題 No.3 ビットすごろく
ユーザー MtBotOMtBotO
提出日時 2017-09-18 21:19:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 807 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 8,520 KB
最終ジャッジ日時 2023-09-14 00:49:20
合計ジャッジ時間 11,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,112 KB
testcase_01 AC 15 ms
8,172 KB
testcase_02 AC 15 ms
7,856 KB
testcase_03 AC 64 ms
7,904 KB
testcase_04 AC 20 ms
8,112 KB
testcase_05 AC 234 ms
8,232 KB
testcase_06 AC 74 ms
7,944 KB
testcase_07 AC 36 ms
8,208 KB
testcase_08 AC 157 ms
8,192 KB
testcase_09 AC 382 ms
8,368 KB
testcase_10 AC 550 ms
8,388 KB
testcase_11 AC 320 ms
8,420 KB
testcase_12 AC 228 ms
8,272 KB
testcase_13 AC 50 ms
7,864 KB
testcase_14 AC 521 ms
8,396 KB
testcase_15 AC 782 ms
8,416 KB
testcase_16 AC 672 ms
8,356 KB
testcase_17 AC 747 ms
8,520 KB
testcase_18 AC 40 ms
8,084 KB
testcase_19 AC 804 ms
8,432 KB
testcase_20 AC 18 ms
8,088 KB
testcase_21 AC 15 ms
8,188 KB
testcase_22 AC 534 ms
8,460 KB
testcase_23 AC 807 ms
8,448 KB
testcase_24 AC 796 ms
8,432 KB
testcase_25 AC 779 ms
8,428 KB
testcase_26 AC 15 ms
8,072 KB
testcase_27 AC 56 ms
8,292 KB
testcase_28 AC 650 ms
8,396 KB
testcase_29 AC 342 ms
8,432 KB
testcase_30 AC 15 ms
8,224 KB
testcase_31 AC 15 ms
8,068 KB
testcase_32 AC 282 ms
8,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())

    # 探索位置情報格納用
    p = [[1,1]]

    # 既に訪れた位置格納
    visited = [1]

    while p:
        # 現在位置を取得
        data = p.pop(0)
        point = data[0]
        cnt = data[1]

        # 目的位置に移動したかチェック
        if point == N :
            print(cnt)
            exit()


        # 移動距離
        v = bin(point)[2:].count("1")
        # 前方移動位置
        f_point = point + v
        # 後方移動位置
        b_point = point - v
        # 移動
        cnt += 1

        # 位置を記憶
        if f_point <= N and  not(f_point in visited):
            p.append([f_point,cnt])
            visited.append(f_point)
        if b_point > 0 and  not(b_point in visited):
            p.append([b_point,cnt])
            visited.append(b_point)

    print(-1)

if __name__ == "__main__":
    main()
0