結果

問題 No.2426 Select Plus or Minus
ユーザー 学ぶマン
提出日時 2025-03-10 11:05:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 746 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2025-03-10 11:06:03
合計ジャッジ時間 8,126 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 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:
            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