結果

問題 No.3299 K-th MMA String
コンテスト
ユーザー れいん
提出日時 2025-12-01 16:03:10
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,185 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,280 ms
コンパイル使用メモリ 279,840 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-12-01 16:03:15
合計ジャッジ時間 4,703 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main()
{
    int N, K;
    cin >> N >> K;
    int now = 0;
    int ans = 0;
    for (int i = 0; i <= 800000 && now < K; i++)
    {
        int tmp = i;
        string bit;

        for (int j = 0; j < 20; j++)
        {
            if (tmp % 2 == 0)
            {
                bit += 'A';
            }
            else
            {
                bit += 'M';
            }
            tmp /= 2;
        }
        reverse(bit.begin(), bit.end());
        for (int j = 0; j < (int)bit.size() - 2; j++)
        {
            if (bit.substr(j, 3) == "MMA")
            {
                now++;
                ans = i;
                break;
            }
        }
    }
    string ans_S;
    for (int i = 0; i < 20; i++)
    {
        if (ans % 2 == 0)
        {
            ans_S += 'A';
        }
        else
        {
            ans_S += 'M';
        }
        ans /= 2;
    }
    reverse(ans_S.begin(), ans_S.end());
    if (ans_S.size() > N)
    {
        ans_S = ans_S.substr(ans_S.size() - N, N);
    }
    else if (ans_S.size() < N)
    {
        ans_S = string(N - ans_S.size(), 'A') + ans_S;
    }
    cout << ans_S;
}
0