結果

問題 No.3 ビットすごろく
ユーザー AEnAEn
提出日時 2022-05-13 16:49:13
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 444 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 77,624 KB
最終ジャッジ日時 2023-09-28 21:09:47
合計ジャッジ時間 5,862 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,608 KB
testcase_01 AC 93 ms
71,400 KB
testcase_02 AC 93 ms
71,520 KB
testcase_03 AC 107 ms
77,404 KB
testcase_04 AC 97 ms
71,732 KB
testcase_05 AC 116 ms
77,408 KB
testcase_06 AC 111 ms
77,228 KB
testcase_07 AC 106 ms
77,248 KB
testcase_08 AC 112 ms
77,528 KB
testcase_09 AC 114 ms
77,432 KB
testcase_10 AC 115 ms
77,564 KB
testcase_11 AC 116 ms
77,328 KB
testcase_12 AC 112 ms
77,592 KB
testcase_13 AC 106 ms
77,272 KB
testcase_14 AC 114 ms
77,452 KB
testcase_15 AC 117 ms
77,572 KB
testcase_16 AC 117 ms
77,608 KB
testcase_17 AC 115 ms
77,060 KB
testcase_18 AC 109 ms
77,464 KB
testcase_19 AC 119 ms
77,492 KB
testcase_20 AC 95 ms
71,668 KB
testcase_21 AC 93 ms
71,184 KB
testcase_22 AC 115 ms
77,480 KB
testcase_23 AC 116 ms
77,624 KB
testcase_24 AC 115 ms
77,496 KB
testcase_25 AC 117 ms
77,316 KB
testcase_26 AC 99 ms
71,344 KB
testcase_27 AC 111 ms
77,284 KB
testcase_28 AC 120 ms
77,560 KB
testcase_29 AC 116 ms
77,508 KB
testcase_30 AC 97 ms
71,184 KB
testcase_31 AC 97 ms
71,556 KB
testcase_32 AC 117 ms
77,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
num = [-1]*N
seen = [False]*N
seen[0] = True
num[0] = 1
d = deque()
d.append(1)
while d:
    n = d.popleft()
    cnt = bin(n).count('1')
    a, b = n+cnt-1, n-cnt-1
    if 0<=a<N and seen[a] == False:
        seen[a] = True
        num[a] = num[n-1]+1
        d.append(a+1)
    if 0<=b<N and seen[b] == False:
        seen[b] = True
        num[b] = num[n-1]+1
        d.append(b+1)
print(num[-1])
0