超时求助
查看原帖
超时求助
1073741
UKE_bound楼主2024/6/5 12:58
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    stack<char> my;
    for(int i=0;i<n;i++){
        my=stack<char>();
        my.push(s[i]);
        for(int j=i+1;j<n;j++){
            if(!my.empty()){
                if(my.top()==s[j]){
                    my.pop();
                    if(my.empty()){
                        ans++;
                    }
                }else{
                    my.push(s[j]);
                }
            }else{
                my.push(s[j]);
            }
        }
    }
    cout<<ans;
    return 0;
}
2024/6/5 12:58
加载中...