CF1476D.Journey

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are n+1n + 1 cities, numbered from 00 to nn. nn roads connect these cities, the ii-th road connects cities i−1i - 1 and ii (i∈[1,n]i \in [1, n]).

Each road has a direction. The directions are given by a string of nn characters such that each character is either L or R. If the ii-th character is L, it means that the ii-th road initially goes from the city ii to the city i−1i - 1; otherwise it goes from the city i−1i - 1 to the city ii.

A traveler would like to visit as many cities of this country as possible. Initially, they will choose some city to start their journey from. Each day, the traveler must go from the city where they currently are to a neighboring city using one of the roads, and they can go along a road only if it is directed in the same direction they are going; i. e., if a road is directed from city ii to the city i+1i + 1, it is possible to travel from ii to i+1i + 1, but not from i+1i + 1 to ii. After the traveler moves to a neighboring city, all roads change their directions to the opposite ones. If the traveler cannot go from their current city to a neighboring city, their journey ends; it is also possible to end the journey whenever the traveler wants to.

The goal of the traveler is to visit as many different cities as possible (they can visit a city multiple times, but only the first visit is counted). For each city ii, calculate the maximum number of different cities the traveler can visit during exactly one journey if they start in the city ii.

共有 n+1n + 1 座城市,编号从 00 到 nn。有 nn 条道路连接这些城市,其中第 ii 条道路连接城市 i−1i - 1 和城市 ii(i∈[1,n]i \in [1, n])。

每条道路具有一个方向。这些方向由一个长度为 nn 的字符串给出,字符串中每个字符为 L 或 R。若第 ii 个字符为 L,表示第 ii 条道路初始方向为从城市 ii 指向城市 i−1i - 1;否则(即为 R),其初始方向为从城市 i−1i - 1 指向城市 ii。

一名旅行者希望尽可能多地访问该国的城市。初始时,旅行者将选择某座城市作为旅程起点。每天,旅行者必须从当前所在城市沿一条道路前往一个相邻城市;但仅当该道路的方向与旅行者行进方向一致时,才允许通行。例如:若某条道路方向为从城市 ii 指向城市 i+1i + 1,则可从 ii 走到 i+1i + 1,但不可反向从 i+1i + 1 走到 ii。旅行者每次移动到相邻城市后,所有道路的方向均立即翻转(即 L 变为 R,R 变为 L)。若旅行者无法从当前城市沿任一道路前往相邻城市,则旅程结束;此外,旅行者也可在任意时刻主动终止旅程。

旅行者的目标是访问尽可能多的互不相同的城市(同一城市可被多次访问,但仅首次访问计入总数)。对每座城市 ii,请计算:若旅行者恰好从城市 ii 出发进行一次旅程,所能访问的不同城市的最大数量。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of two lines. The first line contains one integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5). The second line contains the string ss consisting of exactly nn characters, each character is either L or R.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例由两行组成。第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)。第二行包含一个长度恰好为 nn 的字符串 ss,其中每个字符均为 L 或 R。

保证所有测试用例的 nn 之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, print n+1n + 1 integers. The ii-th integer should be equal to the maximum number of different cities the traveler can visit during one journey if this journey starts in the ii-th city.

对于每个测试用例,输出 n+1n + 1 个整数。其中第 ii 个整数应等于旅行者在一次旅程中最多能够访问的不同城市的数量,前提是该旅程从第 ii 个城市出发。

输入输出样例

  • 输入#1

    2
    6
    LRRRLL
    3
    LRL

    输出#1

    1 3 2 3 1 3 2
    1 4 1 4

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

首页