QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#315260 | #7894. Many Many Heads | hyjsws | WA | 0ms | 14940kb | C++14 | 1.0kb | 2024-01-27 09:52:01 | 2024-01-27 09:52:03 |
Judging History
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(e[u+1]==e[u])
{
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()
{
cin>>z;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)
{
ne[e[a]]++;
if(ne[e[a]]==2)
{
idx=0;
break;
}
else dp(a+1);
}
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: 14940kb
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: 14892kb
input:
2 (([([[([ ]]))])]])]
output:
NO NO
result:
wrong answer expected YES, found NO [1st token]