結果
問題 | No.2766 Delicious Multiply Spice |
ユーザー |
![]() |
提出日時 | 2024-05-31 21:34:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,080 bytes |
コンパイル時間 | 3,582 ms |
コンパイル使用メモリ | 256,760 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-20 22:38:25 |
合計ジャッジ時間 | 4,820 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 8 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } map<ll,string> mp; string f(ll x){ if(mp.contains(x)) return mp[x]; if(x==1){ return mp[x]=""; } string ret="X"; if((x-1)%2==0){ string s=f((x-1)/2); if(s!="X"){ ret=s; ret.push_back('A'); } } if((x-1)%3==0){ string s=f((x-1)/3); if(s!="X"){ ret=s; ret.push_back('B'); } } return mp[x]=ret; } int main(){ ios::sync_with_stdio(false); ll n; cin >> n; string ans=f(n); for(auto i:ans){ assert(i!='X'); } cout << f(n) << '\n'; }