結果

問題 No.2426 Select Plus or Minus
ユーザー flippergo
提出日時 2025-09-07 17:44:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,772 KB
実行使用メモリ 53,948 KB
最終ジャッジ日時 2025-09-07 17:45:04
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
N = int(input())
memo = {}
def f(x):
    if x==1:
        return ""
    if x in memo:
        return memo[x]
    if x%2==0:
        k = 0
        y = x
        while y%2==0:
            y //= 2
            k += 1
        memo[x] = "/"*k+f(y)
        return memo[x]
    else:
        if (3*x+1)%4==0:
            memo[x] = "+"+"/"*2+f((3*x+1)//4)
            return memo[x]
        else:
            memo[x] = "-"+"/"*2+f((3*x-1)//4)
            return memo[x]
ans = f(N)
print(len(ans))
print(ans)
0