結果

問題 No.3 ビットすごろく
ユーザー MarioMario
提出日時 2018-05-19 13:35:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 849 ms / 5,000 ms
コード長 908 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,620 KB
最終ジャッジ日時 2023-09-14 01:01:04
合計ジャッジ時間 12,096 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 17 ms
7,860 KB
testcase_02 AC 18 ms
7,844 KB
testcase_03 AC 69 ms
8,212 KB
testcase_04 AC 22 ms
7,852 KB
testcase_05 AC 252 ms
8,384 KB
testcase_06 AC 78 ms
8,376 KB
testcase_07 AC 37 ms
7,812 KB
testcase_08 AC 168 ms
8,296 KB
testcase_09 AC 410 ms
8,384 KB
testcase_10 AC 580 ms
8,504 KB
testcase_11 AC 347 ms
8,512 KB
testcase_12 AC 240 ms
8,300 KB
testcase_13 AC 53 ms
7,888 KB
testcase_14 AC 543 ms
8,536 KB
testcase_15 AC 828 ms
8,448 KB
testcase_16 AC 716 ms
8,236 KB
testcase_17 AC 804 ms
8,568 KB
testcase_18 AC 44 ms
7,904 KB
testcase_19 AC 846 ms
8,460 KB
testcase_20 AC 19 ms
7,784 KB
testcase_21 AC 16 ms
7,856 KB
testcase_22 AC 559 ms
8,416 KB
testcase_23 AC 849 ms
8,536 KB
testcase_24 AC 847 ms
8,540 KB
testcase_25 AC 827 ms
8,596 KB
testcase_26 AC 16 ms
7,920 KB
testcase_27 AC 61 ms
8,392 KB
testcase_28 AC 700 ms
8,620 KB
testcase_29 AC 359 ms
8,344 KB
testcase_30 AC 16 ms
7,908 KB
testcase_31 AC 16 ms
7,796 KB
testcase_32 AC 309 ms
8,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

def count_1(n):
    return list((bin(n)))[2:].count("1")

class BiSugoroku():
    def __init__(self, n):
        self.n = n
        st = count_1(n)
        self.plus = self.n + st
        self.minus = self.n - st

q = [BiSugoroku(1)]
visited = [1]

step = 0
next_flag = True
find = False

while next_flag:
    next_flag = False
    step += 1

    old_q = q[:]
    q = []

    for b in old_q:

        if  b.n == n:
            next_flag = False
            find = True
            break
        else:
            if b.plus <= n and not (b.plus in visited):
                q.append(BiSugoroku(b.plus))
                visited.append(b.plus)
                next_flag = True

            if 0 < b.minus and not (b.minus in visited):
                q.append(BiSugoroku(b.minus))
                visited.append(b.minus)
                next_flag = True

else:
    print(step if find else -1)
0