結果

問題 No.3 ビットすごろく
ユーザー 👑 H20H20
提出日時 2020-12-01 22:49:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2023-09-14 01:55:14
合計ジャッジ時間 5,384 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,640 KB
testcase_01 AC 96 ms
71,712 KB
testcase_02 AC 96 ms
71,812 KB
testcase_03 AC 119 ms
77,708 KB
testcase_04 AC 106 ms
76,892 KB
testcase_05 AC 116 ms
77,756 KB
testcase_06 AC 113 ms
77,752 KB
testcase_07 AC 115 ms
77,988 KB
testcase_08 AC 115 ms
77,840 KB
testcase_09 AC 117 ms
77,984 KB
testcase_10 AC 119 ms
77,784 KB
testcase_11 AC 116 ms
77,724 KB
testcase_12 AC 113 ms
77,652 KB
testcase_13 AC 112 ms
77,796 KB
testcase_14 AC 116 ms
77,724 KB
testcase_15 AC 119 ms
77,712 KB
testcase_16 AC 118 ms
77,852 KB
testcase_17 AC 121 ms
77,880 KB
testcase_18 AC 107 ms
77,632 KB
testcase_19 AC 124 ms
78,080 KB
testcase_20 AC 98 ms
71,864 KB
testcase_21 AC 95 ms
71,860 KB
testcase_22 AC 117 ms
77,844 KB
testcase_23 AC 117 ms
77,820 KB
testcase_24 AC 113 ms
77,956 KB
testcase_25 AC 116 ms
77,788 KB
testcase_26 AC 90 ms
71,328 KB
testcase_27 AC 106 ms
77,528 KB
testcase_28 AC 118 ms
77,492 KB
testcase_29 AC 113 ms
77,808 KB
testcase_30 AC 92 ms
71,724 KB
testcase_31 AC 86 ms
71,328 KB
testcase_32 AC 115 ms
77,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
L=[]
[L.append([])for _ in range(N+1)]
PASS = [0]*(N+1)

for i in range(N+1):
    cnt = format(i, 'b').count('1')
    if i-cnt >=1:
        L[i].append(i-cnt)
    if i+cnt <=N:
        L[i].append(i+cnt)

q = deque()
qcnt = deque()
q.append(1)
qcnt.append(1)
while len(q) !=0:
    temp = q.popleft()
    cnt = qcnt.popleft()
    if temp ==N:
        print(cnt)
        exit()
    if PASS[temp]==0:
        PASS[temp]=1
        for a in L[temp]:
            q.append(a)
            qcnt.append(cnt+1)
print(-1)
0