結果

問題 No.3 ビットすごろく
ユーザー AtamaokaCAtamaokaC
提出日時 2021-06-19 16:53:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 542 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 78,008 KB
最終ジャッジ日時 2023-09-05 01:00:57
合計ジャッジ時間 5,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,936 KB
testcase_01 AC 89 ms
71,756 KB
testcase_02 AC 86 ms
71,756 KB
testcase_03 AC 102 ms
77,656 KB
testcase_04 AC 95 ms
77,512 KB
testcase_05 AC 112 ms
77,608 KB
testcase_06 AC 105 ms
77,684 KB
testcase_07 AC 99 ms
77,560 KB
testcase_08 AC 111 ms
77,800 KB
testcase_09 AC 112 ms
77,776 KB
testcase_10 AC 112 ms
77,804 KB
testcase_11 AC 111 ms
77,764 KB
testcase_12 AC 112 ms
77,852 KB
testcase_13 AC 103 ms
77,444 KB
testcase_14 AC 115 ms
77,964 KB
testcase_15 AC 114 ms
78,008 KB
testcase_16 AC 114 ms
77,648 KB
testcase_17 AC 117 ms
77,852 KB
testcase_18 AC 105 ms
77,756 KB
testcase_19 AC 115 ms
77,824 KB
testcase_20 AC 90 ms
71,504 KB
testcase_21 AC 89 ms
71,652 KB
testcase_22 AC 118 ms
77,812 KB
testcase_23 AC 123 ms
77,824 KB
testcase_24 AC 117 ms
77,824 KB
testcase_25 AC 119 ms
77,644 KB
testcase_26 AC 93 ms
71,832 KB
testcase_27 AC 109 ms
77,672 KB
testcase_28 AC 120 ms
77,828 KB
testcase_29 AC 116 ms
77,584 KB
testcase_30 AC 93 ms
71,700 KB
testcase_31 AC 89 ms
71,764 KB
testcase_32 AC 114 ms
77,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
inpl = lambda: list(map(int,input().split()))
N = int(input())
visited = [False]*N
q = deque([-1,0])
ans = 0
while q:
    x = q.popleft()
    if x == N-1:
        print(ans)
        exit()
    elif x < 0:
        ans += 1
        if q:
            q.append(-1)
    elif not visited[x]:
        visited[x] = True
        w = bin(x+1).count('1')
        for y in [x-w, x+w]:
            if y < 0 or y > N-1:
                continue
            elif not visited[y]:
                q.append(y)
else:
    print(-1)
0