結果
| 問題 | No.3135 AAABC | 
| コンテスト | |
| ユーザー |  Tatsu_mr | 
| 提出日時 | 2025-05-02 23:29:30 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 148 ms / 2,000 ms | 
| コード長 | 1,369 bytes | 
| コンパイル時間 | 4,202 ms | 
| コンパイル使用メモリ | 289,556 KB | 
| 実行使用メモリ | 21,136 KB | 
| 最終ジャッジ日時 | 2025-05-02 23:29:37 | 
| 合計ジャッジ時間 | 6,011 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()
#define SZ(v) ((int)(v).size())
using lint = long long;
using ld = long double;
int INF = 2000000000;
lint LINF = 1000000000000000000;
struct SetupIo {
    SetupIo() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
} setupio;
int main() {
    int n, s;
    cin >> n >> s;
    vector<string> vec;
    auto kind = [](string s) -> int {
        int res = 0;
        if (count(ALL(s), 'A')) { res++; }
        if (count(ALL(s), 'B')) { res++; }
        if (count(ALL(s), 'C')) { res++; }
        return res;
    };
    auto f = [&](auto f, const string s) -> void {
        if (SZ(s) == n - 1 && kind(s) == 1) {
            return;
        }
        if (SZ(s) == n) {
            if (kind(s) == 3) {
                vec.emplace_back(s);
            }
            return;
        }
        f(f, s + 'A');
        f(f, s + 'B');
        f(f, s + 'C');
    };
    f(f, "");
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)), vec.end());
    cout << (s <= SZ(vec) ? vec[s - 1] : "-1") << "\n";
}
            
            
            
        