forked from Sahaj-Bamba/HacktoberTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc6.cpp
More file actions
50 lines (49 loc) · 699 Bytes
/
c6.cpp
File metadata and controls
50 lines (49 loc) · 699 Bytes
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
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 998244353
using namespace std;
ll func(ll mid);
ll n;
char str[100005];
int main()
{
cin>>n;
scanf("%s",str);
ll low=0,high=0,mid,ans=0;
rep(i,0,n)
if(str[i]=='G')
high++;
//high--;
while(low<=high)
{
mid=(low+high)/2;
if(func(mid)==1)
{
low=mid+1;
ans=mid;
}
else
high=mid-1;
}
printf("%lld",ans);
}
ll func(ll mid)
{
ll cnt=0;
rep(i,0,mid)
if(str[i]=='G')
cnt++;
if(cnt>=mid-1)
return 1;
rep(i,mid,n)
{
if(str[i-mid]=='G')
cnt--;
if(str[i]=='G')
cnt++;
if(cnt>=mid-1)
return 1;
}
return 0;
}