結果
問題 |
No.2766 Delicious Multiply Spice
|
ユーザー |
![]() |
提出日時 | 2024-06-01 18:20:37 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 618 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-12-22 05:23:58 |
合計ジャッジ時間 | 2,396 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 RE * 2 |
other | AC * 10 RE * 21 |
ソースコード
from collections import defaultdict import sys sys.setrecursionlimit(10**7) n = int(input()) d = dict() 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))