QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410181#7894. Many Many HeadsAC_2002WA 1ms5560kbC++201.6kb2024-05-13 17:38:192024-05-13 17:38:19

Judging History

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

  • [2024-05-13 17:38:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5560kb
  • [2024-05-13 17:38:19]
  • 提交

answer

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

int a[1000010];
int b[2][500010];

void solve() {
    string s;
    cin >> s;
    stack<char> st;
    int sum1 = 0, sum2 = 0, temp1 = 0, temp2 = 0;
    if (s[0] == '(' || s[0] == ')') sum1 ++, a[0] = 1, st.push('(');
    else sum2 ++, a[0] = 2, st.push('[');
    for (int i = 1; i < s.size(); i ++ ) {
        if (s[i] == '(' || s[i] == ')') {
            if (st.size() == 0) {
                st.push('(');
                a[i] = 1;
            }
            else if (st.top() == '(') a[i] = -1, st.pop();
            else a[i] = 1, st.push('(');
        } else {
            if (st.size() == 0) {
                st.push('[');
                a[i] = 2;
            }
            else if (st.top() == '[') a[i] = -2, st.pop();
            else a[i] = 2, st.push('[');
        }
    }
    // memset(b, 0, sizeof b);
    int d = 0;
    int flag = 0;
    for (int i = 0; i < s.size(); i ++ ) {
        if (a[i] == 1) {
            d ++ ;
            if (b[0][d] == 1) {
                flag = 1;
                b[0][d] = 0;
                continue;
            }
            b[0][d] = 1;
        } else if (a[i] == -1) d -- ;
        else if (a[i] == 2) {
            d ++ ;
            if (b[1][d] == 1) {
                flag = 1;
                b[1][d] = 0;
                continue;
            }
            b[1][d] = 1;
        } else if (a[i] == -2) d -- ;
    }
    if (flag == 1) cout << "No" << endl;
    else cout << "YES" << endl;
}

signed main() {
    int _;
    cin >> _;
    while (_ -- ) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5560kb

input:

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

output:

YES
No
YES
No
No
No

result:

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