結果
| 問題 | 
                            No.2766 Delicious Multiply Spice
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-05-31 21:43:17 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 847 bytes | 
| コンパイル時間 | 1,379 ms | 
| コンパイル使用メモリ | 105,820 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-12-20 22:57:33 | 
| 合計ジャッジ時間 | 2,798 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 8 | 
| other | AC * 31 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr int iINF = 1'000'000'000;
constexpr ll llINF = 1'000'000'000'000'000'000;
int main () {
    ll N; cin >> N;
    bool end = false;
    int depth = -1;
    vector<char> ans(128);
    auto dfs = [&](auto self, int d, ll val) -> void {
        if (end) return;
        if (val == 1) {
            depth = d;
            end = true;
            return;
        }
        if (!end && (val - 1) % 2 == 0) {
            ans[d] = 'A';
            self(self, d + 1, (val - 1) / 2);
        }
        if (!end && (val - 1) % 3 == 0) {
            ans[d] = 'B';
            self(self, d + 1, (val - 1) / 3);
        }
    };
    dfs(dfs, 0, N);
    for (int i = depth - 1; 0 <= i; i--) {
        cout << ans[i];
    }
    cout << "\n";
}