結果

問題 No.2766 Delicious Multiply Spice
ユーザー playerplayer
提出日時 2024-06-01 18:23:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 666 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 55,444 KB
最終ジャッジ日時 2024-06-01 18:23:14
合計ジャッジ時間 2,916 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,312 KB
testcase_01 AC 42 ms
54,800 KB
testcase_02 AC 42 ms
54,440 KB
testcase_03 AC 40 ms
53,556 KB
testcase_04 AC 41 ms
55,008 KB
testcase_05 AC 43 ms
54,088 KB
testcase_06 AC 41 ms
54,500 KB
testcase_07 AC 41 ms
54,976 KB
testcase_08 AC 41 ms
54,860 KB
testcase_09 AC 43 ms
55,120 KB
testcase_10 AC 43 ms
53,928 KB
testcase_11 AC 42 ms
55,364 KB
testcase_12 AC 42 ms
54,000 KB
testcase_13 AC 42 ms
55,444 KB
testcase_14 AC 40 ms
54,780 KB
testcase_15 AC 41 ms
54,368 KB
testcase_16 AC 43 ms
54,492 KB
testcase_17 AC 42 ms
54,560 KB
testcase_18 AC 42 ms
53,804 KB
testcase_19 AC 41 ms
54,420 KB
testcase_20 AC 41 ms
54,164 KB
testcase_21 AC 41 ms
54,388 KB
testcase_22 AC 42 ms
53,556 KB
testcase_23 AC 42 ms
54,644 KB
testcase_24 AC 41 ms
53,944 KB
testcase_25 AC 42 ms
54,780 KB
testcase_26 AC 42 ms
54,016 KB
testcase_27 AC 41 ms
53,944 KB
testcase_28 AC 42 ms
54,228 KB
testcase_29 AC 42 ms
55,068 KB
testcase_30 AC 42 ms
53,776 KB
testcase_31 AC 41 ms
55,264 KB
testcase_32 AC 42 ms
54,304 KB
testcase_33 AC 42 ms
54,028 KB
testcase_34 AC 41 ms
53,876 KB
testcase_35 AC 40 ms
53,844 KB
testcase_36 AC 41 ms
53,936 KB
testcase_37 AC 41 ms
53,988 KB
testcase_38 AC 41 ms
54,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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