## codeforces 1324 C. Frog Jumps（贪心/二分）

There is a frog staying to the left of the string

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

The frog doesn't want to jump far, so your task is to find the minimum possible value of

Input

The first line of the input contains one integer

The next

It is guaranteed that the sum of lengths of strings over all test cases does not exceed

Output

For each test case, print the answer — the minimum possible value of

Example

Input
6
LRLRRLL
L
LLR
RRRR
LLLLLL
R

Output
3
2
3
1
7
1这个题队友用二分写的== 我当时想的贪心直接扫一遍就行...懒得写了，放上队友的二分代码吧。
#include <bits/stdc++.h>

using namespace std;
const int maxn = 2 * 1e5 + 10;
char s[maxn];
int n;

bool check(int d) {
int p = 0;
while(p + d < n+1) {
bool ok = false;
for(int i = p + d; i >= p + 1; i--)
if(s[i] == 'R') { p = i; ok = true; break; }
if(ok == false) break;
}
return p + d >= n + 1;
}

int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--) {
memset(s, 0, sizeof s);
cin >> s + 1;
n = strlen(s + 1);
int l = 0, r = n + 1;
while(r - l > 1) {
int mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid;
}
printf("%d\n", r);
}
return 0;
}