AT_abc464_g.Celester 2

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The weather for the upcoming NN days is given as a string SS.
If the ii-th character of SS is S, then the weather on day ii is sunny; if it is R, then the weather on day ii is rainy.

You can perform the following operation between 00 and kk times, inclusive:

  • Choose an integer ii with 1≤i≤N1 \le i \le N.
  • If the weather on day ii is sunny, change it to rainy; if it is rainy, change it to sunny.

After performing the operations, you gain happiness based on the final weather according to the following condition:

  • For each integer ii with 1≤i≤N−11 \le i \le N-1, if the weather on day ii after modification is rainy and the weather on day i+1i+1 is sunny, your happiness increases by 11.

For each k=0,1,…,Nk = 0, 1, \dots, N, find the maximum total happiness you can gain by performing the operation at most kk times.

TT test cases are given; solve each.

接下来 NN 天的天气情况由字符串 SS 给出。
若 SS 的第 ii 个字符为 S,则第 ii 天天气为晴天;若为 R,则第 ii 天天气为雨天。

你最多可执行以下操作 kk 次(包括执行 00 次):

  • 选择一个整数 ii,满足 1≤i≤N1 \le i \le N;
  • 若第 ii 天天气为晴天,则将其改为雨天;若为雨天,则改为晴天。

执行完若干次操作后,你的幸福值根据最终天气按如下规则计算:

  • 对每个满足 1≤i≤N−11 \le i \le N-1 的整数 ii,若第 ii 天修改后的天气为雨天且第 i+1i+1 天天气为晴天,则幸福值增加 11。

对每个 k=0,1,…,Nk = 0, 1, \dots, N,求出在最多执行 kk 次操作的前提下所能获得的最大总幸福值。

共给出 TT 组测试数据,请分别求解。

输入格式

The input is given from Standard Input in the following format, where casei\mathrm{case}_i denotes the ii-th test case:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN
SS

输入从标准输入给出,格式如下,其中 casei\mathrm{case}_i 表示第 ii 个测试用例:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例的格式如下:

NN
SS

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

For each test case, let AiA_i be the answer for k=ik = i. Then, output the answer in the following format:

A0A_0 A1A_1 …\dots ANA_N

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

对于每个测试用例,令 AiA_i 表示 k=ik = i 时的答案。然后,按以下格式输出答案:

A0A_0 A1A_1 …\dots ANA_N

输入输出样例

  • 输入#1

    5
    4
    SSSR
    2
    SR
    6
    RSRSRS
    10
    RSRSRRRRRR
    20
    SSRRSSSSRRRSSRRSRSRS

    输出#1

    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

说明/提示

Sample 1 Explanation:
This input contains five test cases.

For the 11st test case:

  • The weather on each day before any operations is sunny, sunny, sunny, rainy in order.
  • For k=0k = 0, no operations can be performed.
    • The weather on each day after operations is sunny, sunny, sunny, rainy, and the total happiness is 00, which is the achievable maximum.
  • For k=1k = 1, for example, changing the weather on day 22 is optimal.
    • The weather on each day after operations is sunny, rainy, sunny, rainy, and the total happiness is 11, which is the achievable maximum.
  • For k=2k = 2, for example, changing the weather on days 11 and 22 is optimal.
    • The weather on each day after operations is rainy, rainy, sunny, rainy, and the total happiness is 11, which is the achievable maximum.
  • For k=3k = 3, for example, changing the weather on days 11, 33, and 44 is optimal.
    • The weather on each day after operations is rainy, sunny, rainy, sunny, and the total happiness is 22, which is the achievable maximum.
  • For k=4k = 4, for example, changing the weather on days 11, 33, and 44 is optimal.
    • The weather on each day after operations is rainy, sunny, rainy, sunny, and the total happiness is 22, which is the achievable maximum.

Constraints

  • 1≤T≤1041 \le T \le 10^4
  • NN is an integer between 22 and 10610^6, inclusive.
  • SS is a string of length NN consisting of S and R.
  • The sum of NN in a single input is at most 10610^6.

样例 1 解释:
该输入包含五个测试用例。

对于第 11 个测试用例:

  • 在执行任何操作前,每天的天气依次为:晴、晴、晴、雨。
  • 当 k=0k = 0 时,无法执行任何操作。
    • 操作后每天的天气仍为:晴、晴、晴、雨,总幸福感为 00,这是可达到的最大值。
  • 当 k=1k = 1 时,例如将第 22 天的天气改为雨是最优策略。
    • 操作后每天的天气为:晴、雨、晴、雨,总幸福感为 11,这是可达到的最大值。
  • 当 k=2k = 2 时,例如将第 11 天和第 22 天的天气均改为雨是最优策略。
    • 操作后每天的天气为:雨、雨、晴、雨,总幸福感为 11,这是可达到的最大值。
  • 当 k=3k = 3 时,例如将第 11、33、44 天的天气分别改为雨、雨、晴(即:第 11 天晴→雨,第 33 天晴→雨,第 44 天雨→晴)是最优策略。
    • 操作后每天的天气为:雨、晴、雨、晴,总幸福感为 22,这是可达到的最大值。
  • 当 k=4k = 4 时,例如将第 11、33、44 天的天气更改(同上),并额外更改一天(如第 22 天晴→雨,但不影响结果)是最优策略。
    • 操作后每天的天气为:雨、晴、雨、晴,总幸福感为 22,这是可达到的最大值。

约束条件

  • 1≤T≤1041 \le T \le 10^4
  • NN 是介于 22 和 10610^6(含)之间的整数。
  • SS 是一个长度为 NN 的字符串,仅由字符 S 和 R 组成。
  • 单组输入中所有测试用例的 NN 之和不超过 10610^6。

输入解题思路,AI测评打分。不知道怎么写?

首页