- 取石子
abc
- 2025-10-4 15:14:51 @
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[1000010];
signed main(){
//freopen("xxx.in","r",stdin);
//freopen("xxx.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
int maxn=0;
map<int,int> mp;
cin>>s;
for(int i=0;i<(int)s.size();i++){
if(s[i]=='G'){
a[i+1]=1;
}else{
a[i+1]=-1;
}
a[i+1]+=a[i];
}
int n=(int)s.size();
for(int i=1;i<=n;i++){
if(a[i]==0){
maxn=i;
}
if(a[i]!=0){
if(mp[a[i]]!=0){
maxn=max(maxn,i-mp[a[i]]);
}else{
mp[a[i]]=i;
}
}
}
cout<<maxn;
return 0;
}
0 条评论
目前还没有评论...
信息
- ID
- 116
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 56
- 已通过
- 9
- 上传者