TLE+RE 35分求优化
查看原帖
TLE+RE 35分求优化
1424067
C_0_a4S楼主2024/10/13 19:56

rt

#include <bits/stdc++.h> 
using namespace std;
char str[200005];

int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",str+1);
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			stack<char>s;
			for(int k=i;k<=j;k++){
				if(s.size()==0)		
				{
					s.push(str[k]);
					continue;
				}
				if(s.top()==str[k])	s.pop();
				else				s.push(str[k]);
			}
			if(s.size()==0)	ans++;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

https://www.luogu.com.cn/record/181792449

2024/10/13 19:56
加载中...