結果

問題 No.3 ビットすごろく
ユーザー MarioMario
提出日時 2018-05-19 13:18:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 870 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 82,128 KB
最終ジャッジ日時 2023-09-10 23:41:59
合計ジャッジ時間 8,309 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,104 KB
testcase_01 AC 79 ms
71,164 KB
testcase_02 AC 76 ms
71,228 KB
testcase_03 AC 783 ms
77,344 KB
testcase_04 AC 110 ms
75,748 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

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

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

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

step = 0
next_flag = True
find = False

while next_flag:
    next_flag = False
    step += 1

    for b in 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