QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#551981 | #7894. Many Many Heads | cyc_43346 | WA | 0ms | 3832kb | C++14 | 1.1kb | 2024-09-07 19:31:20 | 2024-09-07 19:31:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int n;
string s;
bool flag;
bool st[N];
map<char , int> mp = {{'(' , 1} , {')' , 1} , {'[' , 2} , {']' , 2}};
void dfs(int l , int r , int no)
{
if(l >= r)
{
return;
}
if(l)
{
if(mp[s[l]] == no)
{
flag = false;
return;
}
while(mp[s[l]] != mp[s[r]])
{
r--;
}
st[l] = true;
st[r] = true;
}
for(int i = l + 1 ; i <= r ; i++)
{
if(!st[i])
{
dfs(i , r , mp[s[l]]);
}
}
}
void solve()
{
flag = true;
cin >> s;
n = s.size();
s = " " + s;
for(int i = 1 ; i <= n ; i++)
{
st[i] = false;
}
dfs(0 , n , 0);
if(!flag)
{
cout << "No\n";
}
else
{
cout << "Yes\n";
}
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: -100
Wrong Answer
time: 0ms
memory: 3832kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]