QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410178#7894. Many Many HeadsAC_2002TL 3ms7636kbC++201.5kb2024-05-13 17:35:502024-05-13 17:35:50

Judging History

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

  • [2024-05-13 17:35:50]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:7636kb
  • [2024-05-13 17:35:50]
  • 提交

answer

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

int a[1000010];

void solve() {
    string s;
    cin >> s;
    stack<char> st;
    int b[2][500010] = {0};
    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;
    for (int i = 0; i < s.size(); i ++ ) {
        if (a[i] == 1) {
            d ++ ;
            if (b[0][d] == 1) {
                cout << "No" << endl;
                return;
            }
            b[0][d] = 1;
        } else if (a[i] == -1) d -- ;
        else if (a[i] == 2) {
            d ++ ;
            if (b[1][d] == 1) {
                cout << "No" << endl;
                return;
            }
            b[1][d] = 1;
        } else if (a[i] == -2) d -- ;
    }
    cout << "YES" << endl;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 7636kb

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

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: