結果

問題 No.2426 Select Plus or Minus
ユーザー LyricalMaestro
提出日時 2025-07-26 13:32:22
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,143 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 689,400 KB
最終ジャッジ日時 2025-07-26 13:32:32
合計ジャッジ時間 5,178 ms
ジャッジサーバーID
(参考情報)
judge6 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 5 MLE * 1 -- * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/806

from collections import deque

def main():
    N = int(input())

    prev = {N: -1}

    queue = deque()
    queue.append(N)
    while len(queue) > 0:
        w = queue.popleft()

        if w % 2 == 0:
            x = w // 2
            if x not in prev:
                prev[x] = (w, "/")
                queue.append(x)
                if x == 1:
                    break

        else:
            # +
            x = 3 * w + 1
            if x <= 10 ** 18:
                if x not in prev:
                    prev[x] = (w, "+")
                    queue.append(x)
                    if x == 1:
                        break
            # - 
            x = 3 * w - 1
            if x <= 10 ** 18:
                if x not in prev:
                    prev[x] = (w, "-")
                    queue.append(x)
                    if x == 1:
                        break

    answer = []
    x = 1
    while x != N:
        x, y = prev[x]
        answer.append(y)
    answer.reverse()
    print(len(answer))
    print("".join(answer))




                




if __name__ == "__main__":
    main()
0