結果

問題 No.3 ビットすごろく
ユーザー caleicalei
提出日時 2019-12-29 09:55:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 552 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,920 KB
最終ジャッジ日時 2023-09-14 01:33:46
合計ジャッジ時間 1,763 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,496 KB
testcase_01 AC 18 ms
8,540 KB
testcase_02 AC 16 ms
8,668 KB
testcase_03 AC 16 ms
8,588 KB
testcase_04 AC 15 ms
8,484 KB
testcase_05 AC 18 ms
8,692 KB
testcase_06 AC 18 ms
8,524 KB
testcase_07 AC 17 ms
8,496 KB
testcase_08 AC 17 ms
8,720 KB
testcase_09 AC 18 ms
8,768 KB
testcase_10 AC 18 ms
8,760 KB
testcase_11 AC 18 ms
8,744 KB
testcase_12 AC 18 ms
8,632 KB
testcase_13 AC 17 ms
8,600 KB
testcase_14 AC 20 ms
8,760 KB
testcase_15 AC 20 ms
8,808 KB
testcase_16 AC 20 ms
8,860 KB
testcase_17 AC 21 ms
8,920 KB
testcase_18 AC 16 ms
8,624 KB
testcase_19 AC 20 ms
8,876 KB
testcase_20 AC 16 ms
8,492 KB
testcase_21 AC 15 ms
8,476 KB
testcase_22 AC 18 ms
8,884 KB
testcase_23 AC 19 ms
8,808 KB
testcase_24 AC 19 ms
8,912 KB
testcase_25 AC 19 ms
8,848 KB
testcase_26 AC 16 ms
8,664 KB
testcase_27 AC 17 ms
8,504 KB
testcase_28 AC 21 ms
8,780 KB
testcase_29 AC 19 ms
8,684 KB
testcase_30 AC 15 ms
8,492 KB
testcase_31 AC 16 ms
8,556 KB
testcase_32 AC 18 ms
8,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 2019/12/29
# BFS

from collections import deque

n=int(input())


def bfs(s,g):
    visited=[False]*(n+1)
    d=[-1]*(n+1)
    d[s]=1
    visited[0]=True
    visited[s]=True
    que=deque()
    que.append(s)

    while que:
        u=que.popleft()
        step=bin(u).count('1')
        nxt=u+step
        prv=u-step

        for v in [nxt,prv]:
            if v>n:continue
            if visited[v]:continue
            visited[v]=True
            d[v]=d[u]+1
            que.append(v)
            
        

    return d

res=bfs(1,n)
print(res[n])
0