Unkown Error
查看原帖
Unkown Error
837643
BernersWang楼主2024/5/14 20:54
using namespace std;
string s;
int dp[1000005]={};
int main()
{
    getline(cin,s);
    int n;
    n=s.length();
    stack<int> cjn;
    int max=0,count=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='(')
        {
            cjn.push(i);
        }
        else
        {
           if(!cjn.empty())
            {
                int j;
                j=cjn.top();
                cjn.pop();
                if(j>0)
                {
                    dp[i]=dp[j-1]+(i-j+1);
                }
                else
                {
                    dp[i]=i-j+1;
                }
                if(dp[i]>max)
                {
                    max=dp[i]; count=1;
                }
                else if(dp[i]==max)
                {
                    count++;
                }
            }
        }
    }    
    if(max==0)
    {
        count=1;
    }
    cout<<max<<' '<<count;
}```
2024/5/14 20:54
加载中...