QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#396423#7894. Many Many Headsucup-team3294WA 0ms3868kbC++142.0kb2024-04-22 18:49:512024-04-22 18:49:51

Judging History

你现在查看的是最新测评结果

  • [2024-04-22 18:49:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-04-22 18:49:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    string s;
    cin>>s;
    int n=s.size();
    s=' '+s;
    int num1=0,num2=0;
    stack<int> sta1,sta2;
    vector<int> sum1(n+1,0),sum2(n+1,0);
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='('||s[i]==')')
        {
            num1++;
            sum1[i]=sum1[i-1]+1;
            sum2[i]=sum2[i-1];
        }
        else
        {
            num2++;
            sum2[i]=sum2[i-1]+1;
            sum1[i]=sum1[i-1];
        }
    }
    map<int,int> ma1,ma2;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='('||s[i]==')')
        {
            if(sta1.size())
            {
                auto t=sta1.top();
                if((sum2[i]-sum2[t])%2==0)
                {
                    ma1[sta1.size()]++;
                    sta1.pop();
                }
                else
                {
                    sta1.push(i);
                }
            }
            else
            {
                sta1.push(i);
            }

        }
        else
        {
             if(sta2.size())
            {
                auto t=sta2.top();
                if((sum1[i]-sum1[t])%2==0)
                {
                    ma2[sta2.size()]++;
                    sta2.pop();
                }
                else
                {
                    sta2.push(i);
                }
            }
            else
            {
                sta2.push(i);
            }
        }
    }
    for(auto i=ma1.begin();i!=ma1.end();i++)
    {
        if(i->second>=2)
        {
            cout<<"No"<<endl;
            return ;
        }
    }
    for(auto i=ma2.begin();i!=ma2.end();i++)
    {
        if(i->second>=2)
        {
            cout<<"No"<<endl;
            return ;
        }
    }
    cout<<"Yes"<<endl;

}
signed main()
{
    int T;
    cin>>T;
    while(T--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
No
Yes
No
Yes
No

result:

ok 6 token(s): yes count is 3, no count is 3

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3868kb

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]