結果

問題 No.2426 Select Plus or Minus
ユーザー makudo_nald
提出日時 2023-08-19 19:02:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 481 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2024-11-29 14:01:42
合計ジャッジ時間 3,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
ans = []

while N != 1:
    if N % 2 == 0:
        N //= 2
        ans += "/"

    else:
        Np, cp = N * 3 + 1, 0
        Nm, cm = N * 3 - 1, 0

        while Np % 2 == 0:
            Np //= 2
            cp += 1

        while Nm % 2 == 0:
            Nm //= 2
            cm += 1

        if cp > cm:
            N = Np
            ans += "+" + "/" * cp
        else:
            N = Nm
            ans += "-" + "/" * cm

print(len(ans))
print(*ans, sep="")
0