結果

問題 No.3 ビットすごろく
ユーザー Miyu OsanaiMiyu Osanai
提出日時 2019-06-25 11:07:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 770 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 9,912 KB
最終ジャッジ日時 2023-09-14 01:20:34
合計ジャッジ時間 2,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,548 KB
testcase_01 AC 21 ms
8,600 KB
testcase_02 AC 20 ms
8,692 KB
testcase_03 AC 25 ms
8,820 KB
testcase_04 AC 20 ms
8,692 KB
testcase_05 AC 32 ms
9,232 KB
testcase_06 AC 25 ms
8,876 KB
testcase_07 AC 23 ms
8,632 KB
testcase_08 AC 30 ms
9,020 KB
testcase_09 AC 36 ms
9,324 KB
testcase_10 AC 40 ms
9,628 KB
testcase_11 AC 39 ms
9,420 KB
testcase_12 AC 31 ms
9,128 KB
testcase_13 AC 24 ms
8,860 KB
testcase_14 AC 39 ms
9,604 KB
testcase_15 AC 44 ms
9,732 KB
testcase_16 AC 42 ms
9,636 KB
testcase_17 AC 44 ms
9,880 KB
testcase_18 AC 23 ms
8,796 KB
testcase_19 AC 43 ms
9,744 KB
testcase_20 AC 20 ms
8,588 KB
testcase_21 AC 19 ms
8,496 KB
testcase_22 AC 39 ms
9,572 KB
testcase_23 AC 44 ms
9,900 KB
testcase_24 AC 43 ms
9,692 KB
testcase_25 AC 44 ms
9,912 KB
testcase_26 AC 19 ms
8,488 KB
testcase_27 AC 24 ms
8,844 KB
testcase_28 AC 41 ms
9,672 KB
testcase_29 AC 36 ms
9,384 KB
testcase_30 AC 20 ms
8,520 KB
testcase_31 AC 19 ms
8,560 KB
testcase_32 AC 34 ms
9,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def main():
    N = int(input())
    queue = deque()
    L = [(False, i, 0) for i in range(N)]
    L[0] = (True, 1, 1)
    queue.append(L[0])
    while len(queue) > 0:
        now = queue.popleft()
        if now[1] == N:
            print(now[2])
            exit()
        d = count(now[1])
        if (now[1] - d) > 0 and not L[now[1]-d-1][0]:
            L[now[1]-d-1] = (True, now[1] - d, now[2]+1)
            queue.append(L[now[1]-d-1])
        if (now[1] + d) <= N and not L[now[1]+d-1][0]:
            L[now[1]+d-1] = (True, now[1] + d, now[2]+1)
            queue.append(L[now[1]+d-1])
    print(-1)
        

def count(i):
    return len(list(filter(lambda x: x == '1', str(bin(i))[2:])))


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