欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2085A.Serval and String Theory
Serval and String Theory
A string consisting only of lowercase Latin letters is called universal if and only if is lexicographically smaller than the reversal of .
You are given a string consisting of lowercase Latin letters. You are required to make universal. To achieve this, you can perform the following operation on at most times:
- Choose two indices and (), then swap and . Note that if , you do nothing.
Determine whether you can make universal by performing the above operation at most times.
A string is lexicographically smaller than a string of the same length, if and only if the following holds:
- in the first position where and differ, the string has a letter that appears earlier in the alphabet than the corresponding letter in .
The reversal of a string is the string obtained by writing from right to left. For example, the reversal of the string abcad is dacba.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the length of the string , and the maximum number of operations you can perform.
The second line contains a string consisting of lowercase Latin letters.
Output
For each test case, print "YES" if it is possible to make universal by performing the operation at most times. Otherwise, print "NO".
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Note
In the first test case, will keep the same after any operations. However, the reversal of a is still a, so it is impossible to make universal.
In the second test case, the string rev is lexicographically smaller than ver. Thus, is already universal.
In the fifth test case, you can perform the operations as follows:
- Swap and . After this operation, becomes
uniserval; - Swap and . After this operation, becomes
inuserval.
And the string inuserval is universal.
Samples
8
1 10000
a
3 3
rev
6 0
string
6 0
theory
9 2
universal
19 0
codeforcesecrofedoc
19 1
codeforcesecrofedoc
3 1
zzz
NO
YES
NO
YES
YES
NO
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |