CF1324C.Frog Jumps

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a frog staying to the left of the string s=s1s2…sns = s_1 s_2 \ldots s_n consisting of nn characters (to be more precise, the frog initially stays at the cell 00). Each character of ss is either 'L' or 'R'. It means that if the frog is staying at the ii-th cell and the ii-th character is 'L', the frog can jump only to the left. If the frog is staying at the ii-th cell and the ii-th character is 'R', the frog can jump only to the right. The frog can jump only to the right from the cell 00.

Note that the frog can jump into the same cell twice and can perform as many jumps as it needs.

The frog wants to reach the n+1n+1-th cell. The frog chooses some positive integer value dd before the first jump (and cannot change it later) and jumps by no more than dd cells at once. I.e. if the ii-th character is 'L' then the frog can jump to any cell in a range [max(0,i−d);i−1][max(0, i - d); i - 1], and if the ii-th character is 'R' then the frog can jump to any cell in a range [i+1;min(n+1;i+d)][i + 1; min(n + 1; i + d)].

The frog doesn't want to jump far, so your task is to find the minimum possible value of dd such that the frog can reach the cell n+1n+1 from the cell 00 if it can jump by no more than dd cells at once. It is guaranteed that it is always possible to reach n+1n+1 from 00.

You have to answer tt independent test cases.

有一只青蛙位于由 nn 个字符组成的字符串 s=s1s2…sns = s_1 s_2 \ldots s_n 的左侧(更准确地说,青蛙初始时位于第 00 号单元格)。字符串 ss 的每个字符均为 'L' 或 'R'。其含义如下:若青蛙当前位于第 ii 号单元格,且第 ii 个字符为 'L',则青蛙只能向左跳跃;若第 ii 个字符为 'R',则青蛙只能向右跳跃。青蛙只能从第 00 号单元格向右跳跃。

注意:青蛙可以多次跳入同一单元格,且可进行任意次数的跳跃。

青蛙的目标是到达第 n+1n+1 号单元格。在第一次跳跃前,青蛙需选定一个正整数 dd(此后不可更改),且每次跳跃的距离至多为 dd 个单元格。即:若第 ii 个字符为 'L',则青蛙可跳至区间 [max(0,i−d);i−1][max(0, i - d); i - 1] 内的任意单元格;若第 ii 个字符为 'R',则青蛙可跳至区间 [i+1;min(n+1;i+d)][i + 1; min(n + 1; i + d)] 内的任意单元格。

青蛙希望尽可能减少跳跃距离,因此你的任务是找出最小的正整数 dd,使得青蛙能从第 00 号单元格出发,在每次跳跃距离不超过 dd 的前提下,最终到达第 n+1n+1 号单元格。题目保证从第 00 号单元格总能到达第 n+1n+1 号单元格。

你需要回答 tt 个相互独立的测试用例。

输入格式

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

The next tt lines describe test cases. The ii-th test case is described as a string ss consisting of at least 11 and at most 2⋅1052 \cdot 10^5 characters 'L' and 'R'.

It is guaranteed that the sum of lengths of strings over all test cases does not exceed 2⋅1052 \cdot 10^5 (∑∣s∣≤2⋅105\sum |s| \le 2 \cdot 10^5).

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

接下来的 tt 行描述各个测试用例。第 ii 个测试用例由一个字符串 ss 描述,该字符串仅由字符 'L' 和 'R' 组成,长度至少为 11,至多为 2⋅1052 \cdot 10^5。

保证所有测试用例的字符串长度之和不超过 2⋅1052 \cdot 10^5(即 ∑∣s∣≤2⋅105\sum |s| \le 2 \cdot 10^5)。

输出格式

For each test case, print the answer — the minimum possible value of dd such that the frog can reach the cell n+1n+1 from the cell 00 if it jumps by no more than dd at once.

对于每个测试用例,输出答案——即青蛙从单元格 00 出发、每次跳跃距离不超过 dd 的前提下,能够到达单元格 n+1n+1 的最小可能的 dd 值。

输入输出样例

  • 输入#1

    6
    LRLRRLL
    L
    LLR
    RRRR
    LLLLLL
    R

    输出#1

    3
    2
    3
    1
    7
    1

说明/提示

The picture describing the first test case of the example and one of the possible answers:

In the second test case of the example, the frog can only jump directly from 00 to n+1n+1.

In the third test case of the example, the frog can choose d=3d=3, jump to the cell 33 from the cell 00 and then to the cell 44 from the cell 33.

In the fourth test case of the example, the frog can choose d=1d=1 and jump 55 times to the right.

In the fifth test case of the example, the frog can only jump directly from 00 to n+1n+1.

In the sixth test case of the example, the frog can choose d=1d=1 and jump 22 times to the right.

描述示例中第一个测试用例的图片及其中一种可能的答案:

在示例的第二个测试用例中,青蛙只能直接从 00 跳到 n+1n+1。

在示例的第三个测试用例中,青蛙可以选择 d=3d=3,先从单元格 00 跳到单元格 33,再从单元格 33 跳到单元格 44。

在示例的第四个测试用例中,青蛙可以选择 d=1d=1,并向右连续跳跃 55 次。

在示例的第五个测试用例中,青蛙只能直接从 00 跳到 n+1n+1。

在示例的第六个测试用例中,青蛙可以选择 d=1d=1,并向右连续跳跃 22 次。

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

首页