結果

問題 No.3299 K-th MMA String
ユーザー urunea
提出日時 2025-10-07 14:19:05
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 1,022 ms
コンパイル使用メモリ 106,428 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2025-10-07 14:19:10
合計ジャッジ時間 2,677 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

static long long k = 0;

void dfs(long long N, long long K, long long idx, long long ex, vector<char>& p) {
    if (ex == -1 && idx >= 3) {
        if (p[idx - 3] == 'M' && p[idx - 2] == 'M' && p[idx - 1] == 'A') {
            ex = idx;
        }
    }

    if (idx == N) {
        if (ex != -1) {
            k += 1;
            if (k == K) {
                for (char c : p) cout << c;
                cout << '\n';
                exit(0);
            }
        }
        return;
    }

    p.push_back('A');
    dfs(N, K, idx + 1, ex, p);
    p.pop_back(); 
    p.push_back('M');
    dfs(N, K, idx + 1, ex, p);
    p.pop_back(); 
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long N, K;
    cin >> N >> K;

    vector<char> p;
    dfs(N, K, 0, -1, p);

    return 0;
}
0