QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#664412#7894. Many Many Headsnahida_qaqWA 5ms3808kbC++231.9kb2024-10-21 20:29:482024-10-21 20:29:49

Judging History

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

  • [2024-10-21 20:29:49]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3808kb
  • [2024-10-21 20:29:48]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
using namespace std;
const int N=1e6+5,mod1=1e9+7,mod2=998244353;
typedef pair<int,int> pi;
int a[N];
int x[N],y[N];
void solve()
{
    string s;
    cin>>s;
    int n=s.length();
    s=' '+s;
    for(int i=1;i<=n;i++)
    {
        if(s[i]==')')s[i]='(';
        if(s[i]==']')s[i]='[';
    }
    // if(n%2==1)
    // {
    //     cout<<"No"<<'\n';
    //     return ;
    // }
    if(n==2)
    {
        if(s[1]==s[2])cout<<"Yes"<<'\n';
        else cout<<"No"<<'\n';
        return ;
    }
    int res=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]==s[i-1])res++;
        if(i>2)
        {
            if(s[i]==s[i-1]&&s[i-1]==s[i-2])
            {
                cout<<"No"<<'\n';
                return ;
            }
        }
        if(i>3)
        {
            if(s[i]==s[i-1]&&s[i-1]==s[i-2]&&s[i-2]==s[i-3])
            {
                cout<<"No"<<'\n';
                return ;
            }
        }
        x[i]=x[i-1],y[i]=y[i-1];
        if(s[i]=='(')x[i]++;
        else y[i]++;
    }
    if(res>2||res==0)
    {
        cout<<"No"<<'\n';
        return ;
    }
    int ans=0;
    int l=1;
    for(int i=l+1;i<=n;i++)
    {
        if(s[i]==s[l]&&x[i]%2==0&&y[i]%2==0)
        {
            l=i+1;
            ans++;
            break;
        }
    }
    if(s[l]==s[l-1])
    {
        cout<<"No"<<'\n';
        return ;
    }
    for(int i=l+1;i<=n;i++)
    {
        if(s[i]==s[l]&&(x[i]-x[l-1])%2==0&&(y[i]-y[l-1])%2==0)
        {
            l=i+1;
            ans++;
            break;
        }
    }
    if(l==n+1)cout<<"Yes";
    else cout<<"No";
    cout<<'\n';
}
signed main()
{
    io;
    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3808kb

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: 3584kb

input:

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

output:

Yes
No

result:

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

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 3548kb

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
No
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
No
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
N...

result:

wrong answer expected YES, found NO [46th token]