結果
問題 |
No.2766 Delicious Multiply Spice
|
ユーザー |
|
提出日時 | 2024-05-31 21:33:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 2,142 ms |
コンパイル使用メモリ | 205,620 KB |
最終ジャッジ日時 | 2025-02-21 17:33:18 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 8 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n; cin >> n; map<ll, char> pre; pre[n] = 'C'; queue<ll> que; que.push(n); while (!que.empty()) { ll y = que.front(); que.pop(); for (ll s : {2, 3}) { if ((y - 1) % s == 0) { ll x = (y - 1) / s; if (pre.count(x) == 0) { pre[x] = s == 2 ? 'A' : 'B'; que.push(x); } } } } string ans = ""; ll now = 1; while (now < n) { char c = pre[now]; ans.push_back(c); now = now * (c == 'A' ? 2 : 3) + 1; } cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }