結果

問題 No.3135 AAABC
ユーザー rgnerdplayer
提出日時 2025-05-03 03:53:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 3,581 ms
コンパイル使用メモリ 279,380 KB
実行使用メモリ 20,576 KB
最終ジャッジ日時 2025-05-03 03:53:32
合計ジャッジ時間 4,936 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n;
        cin >> n;

        vector<string> a;
        string s;
        vector<int> cnt(3);

        auto rec = [&](auto rec) -> void {
            if (s.size() == n) {
                if (cnt[0] != 0 && cnt[1] != 0 && cnt[2] != 0) {
                    a.push_back(s);
                }
                return;
            }
            for (int i = 0; i < 3; i++) {
                s += 'A' + i;
                cnt[i]++;
                rec(rec);
                s.pop_back();
                cnt[i]--;
            }
        };
        rec(rec);

        int x;
        cin >> x;
        x--;
        if (x >= a.size()) {
            cout << -1 << '\n';
        } else {
            cout << a[x] << '\n';
        }
    };
    
    solve();
    
    return 0;
}
0