QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576530 | #7894. Many Many Heads | Laffey | TL | 347ms | 4864kb | C++20 | 904b | 2024-09-19 20:50:14 | 2024-09-19 20:50:15 |
Judging History
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...