P5660代码
#include <bits/stdc++.h>
using namespace std;
int n,s[100001],top;
char str[100011];
int main()
{
cin >> n >> str + 1;
for(int i = 1;i <= n;i++)
{
if(str[i] == '(')
s[++top] = 0;
else
{
if(str[i] == '[')
s[++top] = 1;
else
{
if(!top)
{
printf("NO\n");
return 0;
}
if(str[i] == ')')
{
if(!s[top])
--top;
else
{
printf("NO\n");
return 0;
}
}
else
{
if(s[top])
--top;
else
{
printf("NO\n");
return 0;
}
}
}
}
}
if(top)
printf("NO\n");
else
printf("YES\n");
return 0;
}