結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0; i<n; i++)
bool chmax(auto& a, auto b) { return a<b ? a=b, true : false; }
bool chmin(auto& a, auto b) { return a>b ? a=b, true : false; }
using ll=long long; const int INF=1e9+10; const ll INFL=4e18;

#ifdef DEBUG
#include "./debug.hpp"
#else
#define debug(...)
#define print_line
#endif


/// @brief ビット演算
namespace Bit{
    /// @brief 1であるビットの個数を返す
    int PopCount(int n) { return __builtin_popcount(n); }

    /// @brief 1であるビットの個数を返す
    int PopCount(ll n) { return __builtin_popcountll(n); }

    /// @brief popcountの偶奇を返す
    int Parity(int n) { return __builtin_parity(n); }

    /// @brief popcountの偶奇を返す
    int Parity(ll n) { return __builtin_parityll(n); }

    /// @brief 最上位ビットの位置を返す
    int TopBit(int n) { return n ? 31-__builtin_clz(n) : -1; }

    /// @brief 最上位ビットの位置を返す
    int TopBit(ll n) { return n ? 63-__builtin_clzll(n) : -1; }

    /// @brief 2進表現の長さを返す
    int BitLength(int n) { return n ? 32-__builtin_clz(n) : 1; }

    //// @brief 2進表現の長さを返す
    int BitLength(ll n) { return n ? 64-__builtin_clzll(n) : 1; }

    /// @brief 最下位ビットの位置を返す
    int LowBit(int n) { return n ? __builtin_ctz(n) : -1; }

    /// @brief 最下位ビットの位置を返す
    int LowBit(ll n) { return n ? __builtin_ctzll(n) : -1; }

    /// @brief 2のべき乗か否かを返す
    bool IsPowerOfTwo(int n) { return n && (n&-n)==n; }

    /// @brief 0~n-1 ビットを立てたビットマスクを返す
    ll Mask(int n) { return (1LL<<n)-1; }

    /// @brief iビット目が立っているか否かを返す
    bool HasBit(ll n,int i) { return (n>>i&1); }

    /// @brief 整数 n の2進表現を返す
    /// @param len ビット数
    /// @param rev 反転するか否か
    string ToBinary(ll n,int len=32,bool rev=false) {
        string ret;
        for(int i=0; i<len; i++) ret+=HasBit(n,rev?len-1-i:i)?'1':'0';
        return ret;
    }
}

//----------------------------------------------------------

void solve() {
    int N,K; cin>>N>>K;
    K--;

    if(N<=20) {
        int cur=0;
        REP(b,1<<N) {
            string s;
            REP(i,N) {
                if(b>>i&1) s.push_back('M');
                else s.push_back('A');
            }
            bool ok=false;
            REP(i,N-3) if(s.substr(i,3)=="MMA") ok=true;
            if(ok) cur++;
            if(cur>K) {
                cout<<s<<endl;
                return;
            }
        }
    }

    for(int i=0; i<=N-3; i++) {
        int cnt=1<<i;
        if(K<=cnt) {
            REP(j,N-i-3) cout<<"A";
            cout<<"MMA";
            string s=Bit::ToBinary(K,i);
            for(char& c: s) {
                if(c=='0') c='A';
                else c='M';
            }
            cout<<s<<endl;
            return;
        }
        else K-=cnt;
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout<<fixed<<setprecision(15);
    int T=1; //cin>>T;
    while(T--) solve();
}
0