Celester 2AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)The weather for the upcoming $N$ days is given as a string $S$.
If the $i$-th character of $S$ is S, then the weather on day $i$ is sunny; if it is R, then the weather on day $i$ is rainy.
接下来 $N$ 天的天气由一个字符串 $S$ 给出。
如果 $S$ 的第 $i$ 个字符是 S,则第 $i$ 天是晴天;如果是 R,则第 $i$ 天是雨天。AI (CI翻译)
You can perform the following operation between $0$ and $k$ times, inclusive:
你可以进行以下操作,操作次数在 $0$ 到 $k$ 次之间(含):AI (CI翻译)
- Choose an integer
$i$with$1 \le i \le N$. - If the weather on day
$i$is sunny, change it to rainy; if it is rainy, change it to sunny.
- 选择一个满足
$1 \le i \le N$的整数$i$。 - 如果第
$i$天是晴天,就将其改为雨天;如果是雨天,就将其改为晴天。
After performing the operations, you gain happiness based on the final weather according to the following condition:
操作完成后,根据最终天气情况获得幸福值:AI (CI翻译)
- For each integer
$i$with$1 \le i \le N-1$, if the weather on day$i$after modification is rainy and the weather on day$i+1$is sunny, your happiness increases by$1$.
- 对于每个满足
$1 \le i \le N-1$的整数$i$,如果修改后第$i$天是雨天,且第$i+1$天是晴天,幸福值增加$1$。
For each $k = 0, 1, \dots, N$, find the maximum total happiness you can gain by performing the operation at most $k$ times.
对于每个 $k = 0, 1, \dots, N$,求最多进行 $k$ 次操作所能获得的幸福值最大值。AI (CI翻译)
$T$ test cases are given; solve each.
给定 $T$ 组测试数据,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \le T \le 10^4$$N$is an integer between$2$and$10^6$, inclusive.$S$is a string of length$N$consisting ofSandR.- The sum of
$N$in a single input is at most$10^6$.
$1 \le T \le 10^4$$N$是一个介于$2$和$10^6$之间的整数(含)。$S$是一个长度为$N$、仅由S和R组成的字符串。- 单个输入中所有测试数据的
$N$之和不超过$10^6$。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case:
输入从标准输入给出,格式如下,其中 $\mathrm{case}_i$ 表示第 $i$ 组测试数据:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试数据的格式如下:AI (CI翻译)
N
S
N
SAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.
输出 $T$ 行。第 $i$ 行应包含第 $i$ 组测试数据的答案。AI (CI翻译)
For each test case, let $A_i$ be the answer for $k = i$. Then, output the answer in the following format:
对于每组测试数据,令 $A_i$ 表示 $k = i$ 时的答案。然后按以下格式输出答案:AI (CI翻译)
A_0 A_1 \dots A_N
A_0 A_1 \dots A_NAI (CI翻译)
样例
5
4
SSSR
2
SR
6
RSRSRS
10
RSRSRRRRRR
20
SSRRSSSSRRRSSRRSRSRS
0 1 1 2 2
0 0 1
3 3 3 3 3 3 3
2 3 4 5 5 5 5 5 5 5 5
5 6 7 8 8 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。