like_rain @ 2023-02-01 16:39:44
rt,我打了一个三重循环暴力解,结果过了
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,s1;
cin>>s;
int len=s.size(),l,maxx=0,r=0,g=0;
for(int i=0;i<len;i++)
for(int j=1;j<=len;j++)
{
s1=s.substr(i,j),l=s1.size(),r=0,g=0;
for(int k=0;k<l;k++)
if(s1[k]=='R') r++;
else g++;
if(r==g) maxx=max(maxx,l);
}
cout<<maxx;
return 0;
}
数据需要加强吗
by like_rain @ 2023-02-01 16:40:50
AC情况
by masonpop @ 2023-02-01 16:57:25
啊?
by jeffstart @ 2023-02-21 19:58:33
666
by luo_xiaoran @ 2023-07-11 08:09:44
666
by livepan @ 2023-07-19 20:40:07
不只是一些水
by jkary @ 2023-07-19 21:05:03
@livepan 是特别水
by sxshm @ 2023-09-25 19:09:52
这~,我还有个更离谱的
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
int sum_g[1000010];
int sum_r[1000010];
bool check(int len){
if(len%2) return false;
for(int l=1;l<=n-len+1;l++){
int r=l+len-1;
if(sum_g[r]-sum_g[l-1]==sum_r[r]-sum_r[l-1]) return true;
}
return false;
}
int main(){
cin>>s;
n=s.size();
int x=pow(2,ceil(log2(n)));
for(int i=x+1;i<=n;i++) s+='#';
for(int i=1;i<=n;i++){
if(s[i-1]=='G') sum_g[i]=sum_g[i-1]+1,sum_r[i]=sum_r[i-1];
if(s[i-1]=='R') sum_r[i]=sum_r[i-1]+1,sum_g[i]=sum_g[i-1];
}
int l=0,r=x;
while(l<r){
int mid=l+r>>1;
if(mid&1) mid++;
if(check(mid)) l=mid+1;
else r=mid-1;
}
printf("%d",l-1);
return 0;
}
这是我写的一个奇怪的二分,竟然过了!!!
可是看了题解后发现这一组样例
RRGGGGRGGGRGGGRRRGRGGRGRGRG
正确答案是18,而我的是16
出题不谨慎,洛谷两行泪
数据过于水,OIer两行泪
by Leo2011 @ 2023-12-03 18:16:05
更离谱的:
#include <bits/stdc++.h>
#define log printf
using namespace std;
const int N = 1e5 + 10; // 题目数据1e6啊
int a[N], mx, len, sum[N];
string s;
int main() {
cin >> s;
len = s.size();
for (int i = 0; i < len; i++) {
if (s[i] == 'G')
a[i] = 1;
else
a[i] = -1;
sum[i + 1] = a[i] + sum[i];
}
for (int i = 1; i < len; i++)
for (int j = i + 1; j <= len; j++)
if (sum[j] - sum[i - 1] == 0)
mx = max(mx, j - i + 1);
log("%d\n", mx);
return 0;
}
这货AC了……
by mayisang @ 2023-12-13 22:09:21
三重循环过1e6 评价是逆天。
by duzichen @ 2024-01-30 13:57:06
DFS也随便跑