This problem can be said to have messed up my thinking. After I figured out the solution, I felt that I was too stupid.
In this problem, we found that jumping to the left is actually not cost-effective. When we jump to the left, the distance will be farther away. All we want to jump is the stone marked "R". At this time, this question is very simple, directly find the coordinate difference of all the stones marked with "R", and take the maximum value.
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
string s;
cin>>s;
vector<int>v;
v.push_back(0);
for(int i=0;i<s.size();++i)
if(s[i]=='R')
v.push_back(i+1);
v.push_back(s.size()+1);
int maxv=-1;
for(int i=1;i<v.size();++i)
maxv=max(maxv,v[i]-v[i-1]);
cout<<maxv<<endl;
}
return 0;
}