結果
問題 |
No.2766 Delicious Multiply Spice
|
ユーザー |
![]() |
提出日時 | 2024-06-01 13:20:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 672 bytes |
コンパイル時間 | 1,375 ms |
コンパイル使用メモリ | 106,176 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-21 21:20:46 |
合計ジャッジ時間 | 2,365 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 8 |
other | AC * 31 |
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <map> using namespace std; using ll = long long; const string no = "#"; map<ll, string> memo; string calc(ll n){ if(n == 1)return ""; if(memo.find(n) != memo.end())return memo[n]; string res = no; if((n - 1) % 2 == 0){ string a = calc((n - 1) / 2); if(a != no)res = a + "A"; } if((n - 1) % 3 == 0){ string a = calc((n - 1) / 3); if(a != no)res = a + "B"; } return memo[n] = res; } ll N; int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; string s = calc(N); cout << s << endl; return 0; }