結果

問題 No.3 ビットすごろく
ユーザー howakurohowakuro
提出日時 2018-12-01 18:10:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 483 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 8,748 KB
最終ジャッジ日時 2023-09-09 06:52:41
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 18 ms
8,548 KB
testcase_03 AC 19 ms
8,608 KB
testcase_04 WA -
testcase_05 AC 18 ms
8,616 KB
testcase_06 AC 19 ms
8,484 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 19 ms
8,504 KB
testcase_13 AC 19 ms
8,540 KB
testcase_14 AC 19 ms
8,640 KB
testcase_15 AC 19 ms
8,548 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 19 ms
8,608 KB
testcase_23 AC 18 ms
8,652 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 19 ms
8,604 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def convert_bit(x):
    return bin(x).count("1")

N = int(input())
q = deque([1])
reach =[0 for i in range(N)] 
while q != deque([]):
    pos = q.popleft()
    reach[pos-1] = 1 
    if pos == N:
        print(N)
        exit()
    move = convert_bit(pos)
    for m in [move,-move]:
        next_pos = m + pos
        if not 1 <= next_pos <= N:
            continue 
        if reach[next_pos - 1] == 1:
            q.append(next_pos)
print(-1)
         
0