玄关求 hack
  • 板块灌水区
  • 楼主hanhoudedidue
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/8/24 16:13
  • 上次更新2023/11/3 01:30:11
查看原帖
玄关求 hack
666072
hanhoudedidue楼主2023/8/24 16:13

P3564 乱搞求法,求hack

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return f*x;
}
inline void print(int x){
	if(x<0) {putchar('-');print(-x);return;}
	if(x>9) print(x/10);putchar(x%10+'0');
}
const int N=1e6+5;
int l,r,n,sum1,sum2,s1,s2,ans,k;
char a[N];
signed main(){
//	freopen("salad.in","r",stdin);
//	freopen("salad.out","w",stdout);
	n=read();l=1,r=n;
	for(int i=1;i<=n;i++) a[i]=getchar();
	while(a[r]=='j') r--;
	while(l<=r){
		while(a[l]=='j') l++;
		int i,k=-1;
		sum1=0,sum2=0;
		for(i=l;i<=r;i++){
			if(a[i]=='p') sum1++,s1++;
			else sum2++,s2++;
			if(sum2>sum1) break; 
			if(s1>=s2) s2=0,s1=0,k=i;
		}
		if(k!=-1) i=k;
//		cerr<<l<<' '<<i<<'\n';
		ans=max(ans,i-l+1);
		l=i+1;s1=s2=0; 
	}
	print(ans);
	return 0;
}
// pjpjj
2023/8/24 16:13
加载中...