CF1427B.Chess Cheater
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game").
The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game.
After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.
Compute the maximum score you can get by cheating in the optimal way.
你很喜欢在线参加国际象棋比赛。
在最近的一次比赛中,你共进行了 n 局对弈。为本题目的需要,每局对弈结果非胜即负(无和棋)。当你输掉一局时,得 0 分;当你获胜时,得 1 或 2 分:若你前一局也获胜,则得 2 分;否则得 1 分。若你在整场比赛的第一局就获胜,则得 1 分(因为不存在“前一局”)。
这 n 局对弈的结果由一个长度为 n 的字符串 s 表示:s 的第 i 个字符为 W 表示你赢了第 i 局,为 L 表示你输了第 i 局。
比赛结束后,你发现网站存在一个漏洞,允许你最多修改 k 局对弈的结果(即最多将 k 个字符从 L 改为 W,或从 W 改为 L)。由于你的唯一目标是提高国际象棋等级分,你决定利用该漏洞作弊。
请计算通过最优作弊方式所能获得的最高得分。
输入格式
Each test contains multiple test cases. The first line contains an integer t (1≤t≤20,000) — the number of test cases. The description of the test cases follows.
The first line of each testcase contains two integers n,k (1≤n≤100,000, 0≤k≤n) – the number of games played and the number of outcomes that you can change.
The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then si=W, if you have lost the i-th game then si=L.
It is guaranteed that the sum of n over all testcases does not exceed 200,000.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤20,000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n,k(1≤n≤100,000,0≤k≤n),分别表示已进行的比赛场数以及你可以更改的比赛结果数量。
每个测试用例的第二行包含一个长度为 n 的字符串 s,其中仅含字符 W 和 L。若你在第 i 场比赛中获胜,则 si=W;若失败,则 si=L。
保证所有测试用例的 n 值之和不超过 200,000。
输出格式
For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.
对于每个测试用例,输出一个整数——通过以最优方式作弊所能获得的最高分数。
输入输出样例
输入#1
8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW
输出#1
7 11 6 26 46 0 1 6
说明/提示
Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game).
An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game.
Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game).
An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11=1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games.
第一个测试用例的解释:在未修改任何比赛结果前,得分为 2。事实上,你赢得了第一场比赛,获得 1 分;你也赢得了第三场比赛,又获得 1 分(而非 2 分,因为你输掉了第二场比赛)。
一种最优的作弊方式是修改第二场和第四场比赛的结果。如此操作后,你将赢得前四场比赛(结果字符串变为 WWWWL)。因此,新的得分为 7=1+2+2+2:第一场比赛得 1 分,第二、第三和第四场比赛各得 2 分。
第二个测试用例的解释:在未修改任何比赛结果前,得分为 3。事实上,你赢得了第四场比赛,获得 1 分;你也赢得了第五场比赛,由于上一场比赛(即第四场)也获胜,因此额外获得 2 分。
一种最优的作弊方式是修改第一、第二、第三和第六场比赛的结果。如此操作后,你将赢得全部六场比赛(结果字符串变为 WWWWWW)。因此,新的得分为 11=1+2+2+2+2+2:第一场比赛得 1 分,其余所有比赛各得 2 分。
输入解题思路,AI测评打分。不知道怎么写?