QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#315272#7894. Many Many HeadshyjswsTL 0ms15476kbC++141.2kb2024-01-27 10:03:282024-01-27 10:03:29

Judging History

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

  • [2024-01-27 10:03:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:15476kb
  • [2024-01-27 10:03:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
typedef long long LL;
LL a,b,c,d,n,m,idx,ans,e[N],ne[N],h[N];
string z;
int dp(int u)
{
    int p=0;
    if(u+1>z.size())
    {
        idx=0;
        return u+1;
    }
    if(e[u+1]==e[u])
    {
        //cout<<"&*("<<endl;
        return u+1;
    }
    else{
        p=dp(u+1);
        if(e[p+1]==e[u])
        {
            return p+1;
        }
        else {
            idx=0;
            return p+1;
        }
    }
}
void solve()
{
    z="";
    cin>>z;a=0;
    a=0;
    memset(e,0,sizeof e);ne[1]=0;ne[0]=0;idx=1;
    for(int i=1;i<=z.size();i++)
    {
        if(z[i-1]=='('||z[i-1]==')')
        e[i]=1;
    }
    a=dp(1);
    while(a<z.size()&&idx==1)
    {
        //cout<<"&*("<<endl;
        ne[e[a]]++;
        if(ne[e[a]]==2)
        {
            idx=0;
            break;
        }
        else a=dp(a+1);
    }
    ne[e[a]]++;
    if(ne[e[a]]==2)
    {
        idx=0;
    }
    if(idx==0)
    {
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
}
int main()
{
    LL N=1;
    cin>>N;
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    while(N--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 15396kb

input:

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

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: -100
Time Limit Exceeded

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No...

result: