結果

問題 No.2426 Select Plus or Minus
ユーザー makudo_naldmakudo_nald
提出日時 2023-08-19 19:00:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 52,224 KB
最終ジャッジ日時 2024-11-29 13:58:44
合計ジャッジ時間 3,823 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)
0