-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path1324C_FrogJumps.cpp
53 lines (40 loc) · 1 KB
/
1324C_FrogJumps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
~ Author : @tridib_2003
~ Title : 1324C. Frog Jumps
~ Link : https://codeforces.com/contest/1324/problem/C
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tc;
cin >> tc;
while (tc--) {
string dir;
cin >> dir;
int len = dir.length();
int prev_r = -1, curr_r = -1, r_diff = 0, last_r_diff = -1, first_r_diff = -1;
for (int i = 0; i < len; ++i) {
if (dir[i] == 'R') {
// Max. diff between two adj. R
prev_r = curr_r;
curr_r = i;
if (prev_r >= 0) {
int curr_diff = curr_r - prev_r;
r_diff = max(r_diff, curr_diff);
}
//Diff between starting position and first R
if (first_r_diff == -1)
first_r_diff = i + 1;
//Diff between destination and nearest R
last_r_diff = len - i;
}
}
if (first_r_diff == -1)
cout << len + 1 << "\n";
else
cout << max( max(r_diff, first_r_diff), last_r_diff) << "\n";
}
return 0;
}