CF1722D.Line

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn people in a horizontal line, each looking either to the left or the right. Each person counts the number of people in the direction they are looking. The value of the line is the sum of each person's count.

For example, in the arrangement LRRLL, where L stands for a person looking left and R stands for a person looking right, the counts for each person are [0,3,2,3,4][0, 3, 2, 3, 4], and the value is 0+3+2+3+4=120+3+2+3+4=12.

You are given the initial arrangement of people in the line. For each kk from 11 to nn, determine the maximum value of the line if you can change the direction of at most kk people.

水平线上有 nn 个人,每人朝左(L)或朝右(R)看。每个人统计其视线方向上的人数。该排列的“值”定义为所有人统计结果的总和。

例如,在排列 LRRLL 中(L 表示朝左看,R 表示朝右看),每个人的统计结果分别为 [0,3,2,3,4][0, 3, 2, 3, 4],因此该排列的值为 0+3+2+3+4=120+3+2+3+4=12。

给定初始排列。对每个 k=1k = 1 到 nn,求在最多改变 kk 个人朝向的前提下,该排列所能达到的最大值。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \leq n \leq 2\cdot10^5) — the length of the line.

The following line contains a string consisting of nn characters, each of which is either L or R, representing a person facing left or right, respectively — the description of the line.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot10^5.

Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2\cdot10^5),表示队列的长度。

接下来的一行包含一个由 nn 个字符组成的字符串,每个字符为 L 或 R,分别表示该位置的人面朝左或面朝右——即队列的描述。

保证所有测试用例的 nn 值之和不超过 2⋅1052\cdot10^5。

请注意,某些测试用例的答案无法用 32 位整数类型表示,因此在编程语言中应至少使用 64 位整数类型(例如 C++ 中的 long long)。

输出格式

For each test case, output nn space-separated non-negative integers — the maximum value of the line if you can change the direction of at most kk people for each kk from 11 to nn, inclusive.

对于每个测试用例,输出 nn 个以空格分隔的非负整数——即对每个从 11 到 nn(含)的 kk,在最多改变 kk 个人朝向的前提下,该队列所能达到的最大值。

输入输出样例

  • 输入#1

    6
    3
    LLR
    5
    LRRLL
    1
    L
    12
    LRRRLLLRLLRL
    10
    LLLLLRRRRR
    9
    LRLRLRLRL

    输出#1

    3 5 5 
    16 16 16 16 16 
    0 
    86 95 98 101 102 102 102 102 102 102 102 102 
    29 38 45 52 57 62 65 68 69 70 
    44 50 54 56 56 56 56 56 56

说明/提示

In the first test case:

  • k=1k=1: change the direction of 11 person to make the line RLR. The total value is 2+1+0=32+1+0=3.
  • k=2k=2: change the direction of 22 people to make the line RLL. The total value is 2+1+2=52+1+2=5.
  • k=3k=3: change the direction of 22 people to make the line RLL. The total value is 2+1+2=52+1+2=5. Note that you have to change the direction of at most kk people.

In the second test case, it is optimal to only change the direction of the first person for all kk from 11 to 55 (that is, make the line RRRLL).

在第一个测试用例中:

  • k=1k=1:改变 11 个人的方向,使队列为 RLR。总价值为 2+1+0=32+1+0=3。
  • k=2k=2:改变 22 个人的方向,使队列为 RLL。总价值为 2+1+2=52+1+2=5。
  • k=3k=3:改变 22 个人的方向,使队列为 RLL。总价值为 2+1+2=52+1+2=5。注意,你最多只能改变 kk 个人的方向。

在第二个测试用例中,对所有从 11 到 55 的 kk 值,最优策略均为仅改变第一个人的方向(即构造队列 RRRLL)。

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

首页