結果
問題 | No.2766 Delicious Multiply Spice |
ユーザー |
|
提出日時 | 2024-05-31 21:33:26 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 2,494 ms |
コンパイル使用メモリ | 212,736 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-20 22:36:34 |
合計ジャッジ時間 | 3,633 ms |
ジャッジサーバーID (参考情報) |
judge3 / 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;}