結果

問題 No.3 ビットすごろく
ユーザー dangodango
提出日時 2023-06-14 21:03:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 577 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 235,536 KB
最終ジャッジ日時 2023-09-05 06:53:35
合計ジャッジ時間 18,339 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,716 KB
testcase_01 AC 92 ms
71,504 KB
testcase_02 AC 92 ms
71,808 KB
testcase_03 AC 124 ms
77,588 KB
testcase_04 AC 110 ms
77,424 KB
testcase_05 AC 310 ms
81,540 KB
testcase_06 AC 129 ms
77,876 KB
testcase_07 AC 117 ms
77,272 KB
testcase_08 AC 178 ms
79,292 KB
testcase_09 AC 1,334 ms
120,320 KB
testcase_10 AC 3,489 ms
235,536 KB
testcase_11 AC 862 ms
101,184 KB
testcase_12 AC 273 ms
80,904 KB
testcase_13 AC 124 ms
77,580 KB
testcase_14 AC 2,966 ms
202,516 KB
testcase_15 TLE -
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 #

def min_moves(N: int) -> int:
    from collections import deque
    queue = deque([(1, 0)])
    visited = set()
    while queue:
        pos, moves = queue.popleft()
        if pos == N:
            return moves + 1
        visited.add(pos)
        next_moves = bin(pos).count('1')
        if pos + next_moves <= N and pos + next_moves not in visited:
            queue.append((pos + next_moves, moves + 1))
        if pos - next_moves > 0 and pos - next_moves not in visited:
            queue.append((pos - next_moves, moves + 1))
    return -1
print(min_moves(int(input())))
0