結果

問題 No.3135 AAABC
ユーザー t98slider
提出日時 2025-05-04 17:49:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 196,436 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-04 17:49:42
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, th, tot = 0;
    cin >> n >> th;
    string ans(n, '?');
    auto dfs = [&](auto dfs, int p, int S) -> void {
        if(p == n){
            tot++;
            if(tot == th){
                cout << ans << '\n';
                exit(0);
            }
            return;
        }
        bool flg = (3 - __builtin_popcount(S)) + p == n;
        for(int i = 0; i < 3; i++){
            if(flg && (S >> i & 1)) continue;
            ans[p] = 'A' + i;
            dfs(dfs, p + 1, S | (1 << i));
        }
    };
    dfs(dfs, 0, 0);
    cout << "-1\n";
}
0