Cang_shu @ 2022-10-20 19:01:51
以下代码AC
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
int f[3000010],ff[3000010];
int ans;
int main(){
getline(cin,s);
int l=s.size();
for(int i=0;i<l;i++){
if(s[i]=='G') ff[i+1]=1;
if(s[i]=='R') ff[i+1]=-1;
}
for(int i=1;i<=l;i++) f[i]=f[i-1]+ff[i];
for(int i=1;i<=l;i++){
for(int j=i+1;j<=l;j++){
if(f[j]-f[i-1]==0){
ans=max(ans,j-(i-1));
}
}
}
cout<<ans;
return 0;
}
而这个代码只有60分
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
int f[3000010],ff[3000010];
int ans;
int main(){
getline(cin,s);
int l=s.size();
for(int i=0;i<l;i++){
if(s[i]=='G') ff[i+1]=1;
if(s[i]=='R') ff[i+1]=2;
}
for(int i=1;i<=l;i++) f[i]=f[i-1]+ff[i];
for(int i=1;i<=l;i++){
for(int j=i+1;j<=l;j++){
if((f[j]-f[i-1])%3==0){
ans=max(ans,j-(i-1));
}
}
}
cout<<ans;
return 0;
}
by Cb_w @ 2022-10-20 19:11:13
%%%巨佬
by Dreamlands @ 2022-10-20 19:21:29
警钟撅烂
by uid_310801 @ 2022-10-20 19:42:06
%%%巨佬
by Merlin_Meow @ 2022-10-20 20:03:36
警钟撅烂