結果

問題 No.3 ビットすごろく
ユーザー netyo715netyo715
提出日時 2021-06-14 11:27:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 530 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,956 KB
最終ジャッジ日時 2023-08-25 20:25:18
合計ジャッジ時間 3,081 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,688 KB
testcase_01 AC 19 ms
8,608 KB
testcase_02 AC 19 ms
8,492 KB
testcase_03 AC 26 ms
8,644 KB
testcase_04 AC 21 ms
8,480 KB
testcase_05 AC 35 ms
8,616 KB
testcase_06 AC 27 ms
8,520 KB
testcase_07 AC 22 ms
8,640 KB
testcase_08 AC 32 ms
8,760 KB
testcase_09 AC 39 ms
8,732 KB
testcase_10 AC 45 ms
8,792 KB
testcase_11 AC 38 ms
8,664 KB
testcase_12 AC 34 ms
8,744 KB
testcase_13 AC 24 ms
8,676 KB
testcase_14 AC 45 ms
8,712 KB
testcase_15 AC 49 ms
8,784 KB
testcase_16 AC 47 ms
8,872 KB
testcase_17 AC 48 ms
8,892 KB
testcase_18 AC 23 ms
8,512 KB
testcase_19 AC 49 ms
8,768 KB
testcase_20 AC 20 ms
8,480 KB
testcase_21 AC 18 ms
8,640 KB
testcase_22 AC 43 ms
8,720 KB
testcase_23 AC 50 ms
8,956 KB
testcase_24 AC 49 ms
8,892 KB
testcase_25 AC 49 ms
8,888 KB
testcase_26 AC 19 ms
8,604 KB
testcase_27 AC 25 ms
8,508 KB
testcase_28 AC 46 ms
8,756 KB
testcase_29 AC 38 ms
8,660 KB
testcase_30 AC 19 ms
8,492 KB
testcase_31 AC 19 ms
8,600 KB
testcase_32 AC 36 ms
8,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
INF = 10**18
dist = [INF]*(N+10)
dist[1] = 0
q = deque()
q.append(1)
while q:
    now = q.popleft()
    cnt = 0
    for i in range(20):
        if (1<<i)&now:
            cnt += 1
    if now-cnt >= 1:
        if dist[now-cnt]==INF:
            dist[now-cnt] = dist[now]+1
            q.append(now-cnt)
    if now+cnt <= N:
        if dist[now+cnt]==INF:
            dist[now+cnt] = dist[now]+1
            q.append(now+cnt)

if dist[N]==INF:
    print(-1)
    exit()
print(dist[N]+1)
0