QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#551981#7894. Many Many Headscyc_43346WA 0ms3832kbC++141.1kb2024-09-07 19:31:202024-09-07 19:31:20

Judging History

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

  • [2024-09-07 19:31:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-09-07 19:31:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 9;

int n;
string s;
bool flag;
bool st[N];
map<char , int> mp = {{'(' , 1} , {')' , 1} , {'[' , 2} , {']' , 2}};

void dfs(int l , int r , int no)
{
    if(l >= r)
    {
        return;
    }
    if(l)
    {
        if(mp[s[l]] == no)
        {
            flag = false;
            return;
        }
        while(mp[s[l]] != mp[s[r]])
        {
            r--;
        }
        st[l] = true;
        st[r] = true;
    }
    for(int i = l + 1 ; i <= r ; i++)
    {
        if(!st[i])
        {
            dfs(i , r , mp[s[l]]);
        }
    }
}

void solve()
{   
    flag = true;
    cin >> s;
    n = s.size();
    s = " " + s;
    for(int i = 1 ; i <= n ; i++)
    {
        st[i] = false;
    }
    dfs(0 , n , 0);
    if(!flag)
    {
        cout << "No\n";
    }
    else
    {
        cout << "Yes\n";
    }
}

int main()
{
    cin.tie(0) -> sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

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

output:

No
No

result:

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