結果

問題 No.3 ビットすごろく
ユーザー motor_radialmotor_radial
提出日時 2019-08-31 20:33:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 834 ms / 5,000 ms
コード長 421 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-09-14 01:26:55
合計ジャッジ時間 11,780 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,664 KB
testcase_01 AC 18 ms
8,588 KB
testcase_02 AC 19 ms
8,540 KB
testcase_03 AC 70 ms
8,480 KB
testcase_04 AC 23 ms
8,620 KB
testcase_05 AC 244 ms
8,668 KB
testcase_06 AC 76 ms
8,496 KB
testcase_07 AC 40 ms
8,512 KB
testcase_08 AC 169 ms
8,580 KB
testcase_09 AC 408 ms
8,680 KB
testcase_10 AC 579 ms
8,676 KB
testcase_11 AC 340 ms
8,760 KB
testcase_12 AC 240 ms
8,744 KB
testcase_13 AC 52 ms
8,668 KB
testcase_14 AC 532 ms
8,860 KB
testcase_15 AC 805 ms
8,840 KB
testcase_16 AC 698 ms
8,756 KB
testcase_17 AC 781 ms
8,884 KB
testcase_18 AC 45 ms
8,512 KB
testcase_19 AC 833 ms
8,784 KB
testcase_20 AC 20 ms
8,548 KB
testcase_21 AC 18 ms
8,436 KB
testcase_22 AC 554 ms
8,684 KB
testcase_23 AC 829 ms
8,932 KB
testcase_24 AC 834 ms
8,812 KB
testcase_25 AC 798 ms
8,900 KB
testcase_26 AC 17 ms
8,488 KB
testcase_27 AC 57 ms
8,532 KB
testcase_28 AC 661 ms
8,868 KB
testcase_29 AC 354 ms
8,680 KB
testcase_30 AC 18 ms
8,508 KB
testcase_31 AC 18 ms
8,456 KB
testcase_32 AC 307 ms
8,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N=int(input())
Node=(1,1)
Route=[1]
Q=deque([Node])
while Q:
    n,count=Q.popleft()
    if n==N:
        print(count);exit()
    mass_2=bin(n).count("1")
    if n+mass_2<=N and n+mass_2 not in Route:
        Route.append(n+mass_2)
        Q.append((n+mass_2,count+1))
    if n-mass_2>1 and n-mass_2 not in Route:
        Route.append(n-mass_2)
        Q.append((n-mass_2,count+1))
print(-1)
0