欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1706A.Another String Minimization Problem
Another String Minimization Problem
You have a sequence of length , consisting of integers between and . You also have a string , consisting of characters B.
You are going to perform the following operations.
- At the -th () operation, you replace either the -th or the -th character of with
A. You can replace the character at any position multiple times through the operations.
Find the lexicographically smallest string you can get after these operations.
A string is lexicographically smaller than a string of the same length if and only if in the first position where and differ, the string has a letter that appears earlier in the alphabet than the corresponding letter in .
Input
The first line contains the number of test cases ().
The first line of each test case contains two integers and () — the length of the sequence and the length of the string respectively.
The second line contains integers () — the sequence .
Output
For each test case, print a string of length — the lexicographically smallest string you can get. Each character of the string should be either capital English letter A or capital English letter B.
Note
In the first test case, the sequence . One of the possible solutions is the following.
- At the -st operation, you can replace the -st character of with
A. After it, becomesABBBB. - At the -nd operation, you can replace the -th character of with
A(since ). After it, becomesABBBA. - At the -rd operation, you can replace the -rd character of with
A. After it, becomesABABA. - At the -th operation, you can replace the -st character of with
A. After it, remains equal toABABA.
The resulting string is ABABA. It is impossible to produce a lexicographically smaller string.
In the second test case, you are going to perform only one operation. You can replace either the -nd character or -th character of with A. You can get strings BABBB and BBBAB after the operation. The string BABBB is the lexicographically smallest among these strings.
In the third test case, the only string you can get is A.
In the fourth test case, you can replace the -st and -nd characters of with A to get AABB.
In the fifth test case, you can replace the -st and -rd characters of with A to get ABABBBB.
Samples
6
4 5
1 1 3 1
1 5
2
4 1
1 1 1 1
2 4
1 3
2 7
7 5
4 5
5 5 3 5
ABABA
BABBB
A
AABB
ABABBBB
ABABA
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |