結果

問題 No.3299 K-th MMA String
コンテスト
ユーザー cologne
提出日時 2025-11-14 15:15:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2025-11-14 15:15:04
合計ジャッジ時間 3,387 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(2*10**5)


def input(): return sys.stdin.readline().rstrip('\n')


def main():
    n, k = map(int, input().split())

    arr = []
    mma = 0

    def gen():
        nonlocal arr, k, mma
        if len(arr) == n:
            if mma > 0:
                k -= 1
            return ''.join(arr) if k == 0 else None

        mm = arr[-2:] == ['M', 'M']
        arr.append('A')
        if mm:
            mma += 1
        ans = gen()
        if ans is not None:
            return ans
        if mm:
            mma -= 1
        arr.pop()

        arr.append('M')
        ans = gen()
        if ans is not None:
            return ans
        arr.pop()
        return None

    print(gen())


if __name__ == '__main__':
    main()
0