結果

問題 No.3 ビットすごろく
ユーザー flippergoflippergo
提出日時 2020-12-21 18:37:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 435 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 77,932 KB
最終ジャッジ日時 2023-09-14 01:55:35
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,500 KB
testcase_01 AC 94 ms
71,184 KB
testcase_02 AC 94 ms
71,492 KB
testcase_03 AC 110 ms
77,816 KB
testcase_04 AC 96 ms
71,740 KB
testcase_05 AC 114 ms
77,672 KB
testcase_06 AC 110 ms
77,648 KB
testcase_07 AC 107 ms
77,272 KB
testcase_08 AC 114 ms
77,932 KB
testcase_09 AC 116 ms
77,732 KB
testcase_10 AC 116 ms
77,888 KB
testcase_11 AC 114 ms
77,680 KB
testcase_12 AC 113 ms
77,672 KB
testcase_13 AC 107 ms
77,800 KB
testcase_14 AC 116 ms
77,536 KB
testcase_15 AC 117 ms
77,740 KB
testcase_16 AC 118 ms
77,736 KB
testcase_17 AC 117 ms
77,864 KB
testcase_18 AC 109 ms
77,640 KB
testcase_19 AC 118 ms
77,392 KB
testcase_20 AC 97 ms
71,592 KB
testcase_21 AC 94 ms
71,584 KB
testcase_22 AC 117 ms
77,708 KB
testcase_23 AC 119 ms
77,740 KB
testcase_24 AC 120 ms
77,772 KB
testcase_25 AC 118 ms
77,736 KB
testcase_26 AC 96 ms
71,184 KB
testcase_27 AC 109 ms
77,672 KB
testcase_28 AC 117 ms
77,568 KB
testcase_29 AC 115 ms
77,840 KB
testcase_30 AC 99 ms
71,712 KB
testcase_31 AC 95 ms
71,576 KB
testcase_32 AC 116 ms
77,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
hist = [0 for _ in range(N+1)]
que = deque([(1,1)])
hist[1]=1
flag = 0
while que:
    x,d = que.popleft()
    if x==N:
        flag = 1
        break
    n = bin(x)[2:].count("1")
    if x-n>=1 and hist[x-n]==0:
        hist[x-n]=1
        que.append((x-n,d+1))
    if x+n<=N and hist[x+n]==0:
        hist[x+n]=1
        que.append((x+n,d+1))
if flag==0:
    print(-1)
else:
    print(d)
0