結果

問題 No.2766 Delicious Multiply Spice
ユーザー elphe
提出日時 2024-06-27 15:40:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 879 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 79,816 KB
最終ジャッジ日時 2025-02-22 00:46:53
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 17 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

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

    long long N;
    cin >> N;
    set<long long> taste;
    set<long long>::iterator itr, temp;
    string ans;
    taste.insert(1);

    for (itr = taste.begin(); itr != taste.end() && *itr < N; ++itr)
        taste.insert(*itr * 2 + 1), taste.insert(*itr * 3 + 1);

    if (*itr != N)
    {
        cout << "Impossible!\n";
        return 0;
    }

    while (*itr != 1)
    {
        if ((*itr - 1) % 2 == 0 && (temp = taste.find((*itr - 1) / 2)) != taste.end())
            ans.push_back('A'), itr = temp;
        else if ((*itr - 1) % 3 == 0 && (temp = taste.find((*itr - 1) / 3)) != taste.end())
            ans.push_back('B'), itr = temp;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    return 0;
}
0