当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7044:Fall with Fake Problem

题目描述
A boy, whose ID is smzzl, loves solving problems on Codeforces. Some day, he was solving the following problem:

Given a string $S$, find the lexicographical-smallest string $T$, whose lexicographical order is no smaller than $S$, the times each letter appears in $T$ are multiples of $k$, and $|S|=|T|$.

"The problem is too easy! I want a harder one!"

So, he modified the problem. He no longer requires the times each letter appears in $T$ to be a multiple of $k$. Instead, he wants them to be a factor of $k$ or 0.

The problem actually becomes harder, but not so much harder. Fall, the teammate of smzzl, solved it immediately! And now, Fall wants you to solve it, so he can check his answer.
输入解释
The input consists of multiple test cases.

The first line contains an integer $T$ ($1 \leq T \leq 32$) -- the number of test cases.

For each test case, there are two lines.

The first line contains two integers $n,k$($1 \leq n,k \leq 10^5$), which are the length of $S$ and the argument mentioned above.

The second line contains a string $S$, which only contains lower case letters.

It is guaranteed that the sum of $|S|$ over all test cases does not exceed $10^6$.
输出解释
For each test case, output a string $T$ in a line, which is your answer. If there is no such $T$, output '-1' instead (without quotes).
输入样例
2
5 6
aaaaa
10 18
abcabcabcd
输出样例
aaabb
abcabcabcd

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7044

最后修改于 2021-10-23T19:11:10+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 524288/524288K(Java/Others)