結果

問題 No.2766 Delicious Multiply Spice
ユーザー june19312
提出日時 2024-05-31 21:54:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 856 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,112 KB
実行使用メモリ 54,272 KB
最終ジャッジ日時 2024-12-20 23:16:02
合計ジャッジ時間 3,268 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 8
other WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

N = int(input())
ans = []
while N > 1:
    if N%2 == 0:
        ans.append("B")
        N-=1
        N//=3
    else:
        ans.append("A")
        N -= 1
        if N % 2 == 0:
            N//=2
        else:
            N//3

ans.reverse()
print("".join(ans))

def dfs(x,y):
    if x <= 1:
        if x == 1:
            print("".join(y[::-1]))
            exit()
        else:
            return

    if (x-1)%2 == 0 and (x-1)%3 == 0:
        y.append("B")
        dfs((x-1)//3,y)
        y.pop()
    else:
        return

    if (x-1)%2 == 0:
        y.append("A")
        dfs((x-1)//2,y)
        y.pop()
    else:
        return

    if (x-1)%3 == 0:
        y.append("B")
        dfs((x-1)//3,y)
        y.pop()
    else:
        return

dfs(N,[])
0