QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576530#7894. Many Many HeadsLaffeyTL 347ms4864kbC++20904b2024-09-19 20:50:142024-09-19 20:50:15

Judging History

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

  • [2024-09-19 20:50:15]
  • 评测
  • 测评结果:TL
  • 用时:347ms
  • 内存:4864kb
  • [2024-09-19 20:50:14]
  • 提交

answer

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int MAXN = 1e5 + 10;
int st[MAXN], top;
int v[MAXN][2];
string s;

inline void init()
{
    top = 0;
    memset(st, -1, sizeof st);
    memset(v, 0, sizeof v);
}

inline int type(const char &c)
{
    return (c == '[' || c == ']') ? 1 : 0;
}

inline bool check()
{
    for (auto p = s.begin(); p != s.end(); p++) {
        int t = type(*p);
        if (st[top] == t) {
            v[top][t]++;
            if (v[top][t] == 2) return false;
            top--;
        }
        else {
            st[++top] = t;
        }
    }
    return true;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("./in", "r", stdin);
#endif
    int t;
    cin >> t;
    while (t--) {
        init();
        cin >> s;
        cout << (check() ? "Yes" : "No") << endl;
    }
    return 0;
}

详细

Test #1:

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

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

input:

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

output:

Yes
No

result:

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

Test #3:

score: 0
Accepted
time: 347ms
memory: 4864kb

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:

ok 15134 token(s): yes count is 132, no count is 15002

Test #4:

score: -100
Time Limit Exceeded

input:

100000
][[][[
())))(
)())))
]]][[[
)[]))(
()[[)(
)())))
[[[][]
[][][]
))[]]]
]]]][[
][]]][
(][)))
((([](
][[]]]
)([)([
))()((
[)[[)[
((()))
)(][[]
][[[[[
()((((
][][]]
][)()(
]]]]][
(()(()
)([((]
[][[]]
]][]][
)((())
][[[[[
[)[[([
(([[)(
(((())
)((()(
))()()
()((((
[[][][
))[])(
(((()(
]]][[]
()[[]]...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No...

result: