結果

問題 No.2766 Delicious Multiply Spice
ユーザー ypww
提出日時 2024-05-31 22:04:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,297 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 94,408 KB
最終ジャッジ日時 2025-02-21 17:54:50
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 17 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <tuple>
#include <unordered_set>

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // cout << fixed << setprecision(18);
    
    ll n;
    cin>>n;

    ll now = 1;
    queue<tuple<ll,ll,ll>> q;
    unordered_set<ll> visited; // 訪問済みの状態を追跡
    q.push({now,0,0});
    visited.insert(now); // 初期状態を訪問済みに設定

    while(!q.empty()){
        auto [now, s, sz] = q.front(); q.pop();
        if (now==n){
            string ans = "";
            while(sz){
                if (s & 1){
                    ans += 'B';                    
                }else{
                    ans += 'A';
                }
                s >>= 1;
                sz -= 1;
            }
            cout << ans << endl;
            return 0;
        }
        if (now * 2 + 1 <= n && visited.find(now * 2 + 1) == visited.end()){
            q.push({now * 2 + 1, s, sz + 1});
            visited.insert(now * 2 + 1);
        }
        if (now * 3 + 1 <= n && visited.find(now * 3 + 1) == visited.end()){
            q.push({now * 3 + 1, s + (1LL << sz), sz + 1});
            visited.insert(now * 3 + 1);
        }
    }
    cout << endl;   
    return 0;
}
0