結果

問題 No.2766 Delicious Multiply Spice
ユーザー elphe
提出日時 2025-05-17 12:05:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 993 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 118,536 KB
実行使用メモリ 338,808 KB
最終ジャッジ日時 2025-05-17 12:05:26
合計ジャッジ時間 9,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 17 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

static inline string solve(const uint64_t N) noexcept
{
	vector<uint64_t> stack;
	unordered_map<uint64_t, char> cake_status;
	cake_status.insert({ 3, 'A' }), cake_status.insert({ 4, 'B' });
	stack.push_back(3), stack.push_back(4);
	while (!stack.empty())
	{
		const auto cur = stack.back();
		stack.pop_back();
		if (cur < N)
		{
			cake_status[cur * 2 + 1] = 'A', stack.push_back(cur * 2 + 1);
			cake_status[cur * 3 + 1] = 'B', stack.push_back(cur * 3 + 1);
		}
	}

	string ans;
	uint64_t cur = N;
	while (cur != 1)
	{
		ans.push_back(cake_status[cur]);
		switch (cake_status[cur])
		{
		case 'A':
			cur = (cur - 1) >> 1;
			break;

		case 'B':
			cur = (cur - 1) / 3;
			break;
		}
	}

	reverse(ans.begin(), ans.end());
	return ans;
}

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	uint64_t N;
	cin >> N;

	cout << solve(N) << '\n';
	return 0;
}
0