QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#671718#7894. Many Many Headswsy_jim#WA 7ms3868kbC++141.5kb2024-10-24 14:10:492024-10-24 14:10:49

Judging History

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

  • [2024-10-24 14:10:49]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3868kb
  • [2024-10-24 14:10:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<iomanip>
using namespace std;

template<typename T>
inline void read(T &x){
    x=0;bool flg=0;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') flg=1;
    for(;isdigit(c);c=getchar()) x=x*10+(c^48);
    if(flg) x=-x;
}

int n;
const int N = 1e6 + 10;
string s;
int a[N];
stack<int> stk;

int main(){

    int T;
    cin >> T;
    while (T--)
    {
        cin >> s;
        int n = s.size();
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(' || s[i] == ')')
                a[i + 1] = 0;
            else
                a[i + 1] = 1;
        }
        while (!stk.empty())
            stk.pop();
        int num0 = 0, num1 = 0;

        for (int i = 1; i <= n; i++)
        {
            if (stk.empty() || stk.top() != a[i])
                stk.push(a[i]);
            else {
                stk.pop();
                if (stk.empty()) {
                    if (a[i] == 0)
                        num0++;
                    else
                        num1++;
                }
            }
        }
        if (stk.empty() && ((num0 == 0 && num1 == 1) || (num0 == 1 && num1 == 0) || (num0 == 1 && num1 == 1)))
            printf("Yes\n");
        else
            printf("No\n");
    }

    return 0;
}

詳細信息

Test #1:

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

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

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: 7ms
memory: 3868kb

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

result:

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