結果

問題 No.3 ビットすごろく
ユーザー Kiri8128Kiri8128
提出日時 2020-09-05 18:19:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 636 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 77,836 KB
最終ジャッジ日時 2023-09-14 01:50:13
合計ジャッジ時間 5,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,396 KB
testcase_01 AC 92 ms
71,520 KB
testcase_02 AC 91 ms
71,512 KB
testcase_03 AC 109 ms
77,544 KB
testcase_04 AC 99 ms
76,492 KB
testcase_05 AC 106 ms
77,452 KB
testcase_06 AC 104 ms
77,560 KB
testcase_07 AC 102 ms
77,536 KB
testcase_08 AC 104 ms
77,552 KB
testcase_09 AC 104 ms
77,608 KB
testcase_10 AC 105 ms
77,412 KB
testcase_11 AC 104 ms
77,632 KB
testcase_12 AC 107 ms
77,448 KB
testcase_13 AC 106 ms
77,284 KB
testcase_14 AC 107 ms
77,336 KB
testcase_15 AC 107 ms
77,632 KB
testcase_16 AC 105 ms
77,648 KB
testcase_17 AC 106 ms
77,572 KB
testcase_18 AC 107 ms
77,516 KB
testcase_19 AC 103 ms
77,356 KB
testcase_20 AC 89 ms
71,504 KB
testcase_21 AC 93 ms
71,388 KB
testcase_22 AC 103 ms
77,796 KB
testcase_23 AC 106 ms
77,556 KB
testcase_24 AC 106 ms
77,836 KB
testcase_25 AC 105 ms
77,412 KB
testcase_26 AC 92 ms
71,696 KB
testcase_27 AC 104 ms
77,540 KB
testcase_28 AC 108 ms
77,448 KB
testcase_29 AC 105 ms
77,400 KB
testcase_30 AC 88 ms
71,600 KB
testcase_31 AC 89 ms
71,432 KB
testcase_32 AC 104 ms
77,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def popcount(x):
    x -= (x >> 1) & 0x5555
    x = (x & 0x3333) + ((x >> 2) & 0x3333)
    x = (x + (x >> 4)) & 0x0f0f
    x += x >> 8
    return x & 0x1f

N = int(input())

X = [[] for i in range(N + 1)]
for i in range(1, N):
    pc = popcount(i)
    if i - pc > 0:
        X[i].append(i - pc)
    if i + pc <= N:
        X[i].append(i + pc)

def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 1
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D

print(BFS(N + 1, X, 1)[-1])

0