結果
| 問題 |
No.2766 Delicious Multiply Spice
|
| コンテスト | |
| ユーザー |
player
|
| 提出日時 | 2024-06-01 18:23:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 666 bytes |
| コンパイル時間 | 261 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 54,016 KB |
| 最終ジャッジ日時 | 2024-12-22 05:27:35 |
| 合計ジャッジ時間 | 3,501 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 8 |
| other | AC * 31 |
ソースコード
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))
player