結果

問題 No.2426 Select Plus or Minus
ユーザー 学ぶマン
提出日時 2025-03-10 11:06:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2025-03-10 11:06:51
合計ジャッジ時間 3,977 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 10**18

N = int(input())

def solve(m:int, history:list):
    
    if m == 1:
        if len(history) <= 10000:
            print(len(history))
            exit(print(''.join(history)))
        else:
            return

    if m%2 == 0:
        m //= 2
        history.append('/')
        solve(m, history)
        history.pop()
        m *= 2

    else:
        if 3*m + 1 < INF:
            m = 3*m + 1
            history.append('+')
            solve(m, history)
            history.pop()
            m = (m - 1)//3

        if 3*m - 1 < INF:
            m = 3*m - 1
            history.append('-')
            solve(m, history)
            history.pop()
            m = (m + 1)//3

solve(N, [])
0