跳到正文

剪贴板

剪贴板 erv17w23

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2000200;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')
          f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline void write(ll x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9)
	  write(x/10);
	putchar(x%10+'0');
}
ll n,ans=0;
char s[N];
stack<char> t;
int main(){
	n=read();
	scanf("%s",s+1);
	for(int i=2;i<=n;i++){
		while(!t.empty())
		  t.pop();
		t.push(s[i]);
		for(int j=(i-1);j>=1;j--){
			if(!t.empty()&&(s[j]==t.top()))
			  t.pop();
			else
			  t.push(s[j]);
			if(t.empty())
			  ans++;
		}
	}
	write(ans);
	return 0;
}