5450.Not Another Constructive!

Time Limit: 1s Memory Limit: 256MB

Sick of solving geometry problems, you decide to solve the following constructive problem: find a string of length $n$ that contains exactly $k$ not necessarily contiguous subsequences of NAC.

This problem seems too familiar though. Here’s the twist - your friend has given you part of the string, so you must fill in the remaining characters!

Input Format(From the terminal/stdin)

The first line of input contains two integers $n (1 ≤ n ≤ 40)$ and $k (0 ≤ k ≤ 2,500)$, where $n$ is the length of the string and $k$ is the number of not necessarily contiguous subsequences of NAC that the output must contain.

The second line contains a string of length exactly $n$, consisting only of uppercase letters and/or question marks.

Output Format(To the terminal/stdout)

Output a string of upper case letters, replacing each question mark in the input string with an uppercase letter so that the resulting string has exactly $k$ subsequences of NAC. If this is not possible, output $-1$. Any uppercase letters in the input string must be kept in their position. There may be multiple possible solutions for any given test case; any correct solution will be accepted.

Sample Input 1

Copy
22 2
N??A??????C???????????
  · \n
                      \n

Sample Output 1 special judge

Copy
NOTANOTHERCONSTRUCTIVE
                      \n

Sample Input 2

Copy
18 0
COUNTINGSATELLITES
  · \n
                  \n

Sample Output 2 special judge

Copy
COUNTINGSATELLITES
                  \n

Sample Input 3

Copy
2 1
??
 · \n
  \n

Sample Output 3 special judge

Copy
-1
  \n
Source: NAC 2024

Submit

请先 登录

© 2025 FAQs