結果

問題 No.2766 Delicious Multiply Spice
コンテスト
ユーザー player
提出日時 2024-06-01 18:23:07
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 666 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 166 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 53,760 KB
最終ジャッジ日時 2026-05-28 14:22:41
合計ジャッジ時間 3,985 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)

n = int(input())
d = defaultdict(bool)

if n == 1:
    print("")
    exit()

d[1] = True


def dfs(now):
    if now in d:
        return d[now]
    if (now - 1) % 2 == 0 and dfs((now - 1) // 2):
        d[now] = True
        return True
    if (now - 1) % 3 == 0 and dfs((now - 1) // 3):
        d[now] = True
        return True
    return False


dfs(n)

now = n
ans = []
while now > 1:
    if (now - 1) % 2 == 0 and d[(now - 1) // 2]:
        ans.append("A")
        now = (now - 1) // 2
    else:
        ans.append("B")
        now = (now - 1) // 3

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