結果
| 問題 | No.3299 K-th MMA String | 
| コンテスト | |
| ユーザー |  sasa8uyauya | 
| 提出日時 | 2025-10-11 03:35:09 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 661 ms / 2,000 ms | 
| コード長 | 494 bytes | 
| コンパイル時間 | 279 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 164,260 KB | 
| 最終ジャッジ日時 | 2025-10-11 03:35:18 | 
| 合計ジャッジ時間 | 8,639 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 | 
ソースコード
n,K=map(int,input().split())
import sys
sys.setrecursionlimit(10**6)
s=[]
q=[0]
def f():
  global K
  if len(s)==n-2:
    if q[-1]==0 and s[-1:]!=list("M"):
      return
  if len(s)==n-1:
    if q[-1]==0 and s[-2:]!=list("MM"):
      return
  if len(s)==n:
    if q[-1]==0:
      return
    K-=1
    if K==0:
      print("".join(s))
      exit()
    return
  for c in "AM":
    s.append(c)
    q.append(q[-1]|(len(s)>=3 and s[-3:]==list("MMA")))
    f()
    s.pop()
    q.pop()
  return
f()
            
            
            
        