#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=105,S=15,M=27,INF=101;
int t,n,top,ind,now,ans,k;
char c[S],s[N][S],buf[S];
int st[N],d[M],dfn[N],stf[N],mo[N];
int l[N],r[N];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%s",c);
k=0;
if(c[2]=='n')
for(int i=4;c[i]!=')';i++)
k=k*10+c[i]-'0';
memset(s,0,sizeof(s));
for(int i=1;i<=n;i++)
{
scanf("%s",buf);
strcat(s[i]+1,buf);
if(buf[0]=='F')
{
scanf("%s",buf);
strcat(s[i]+1," ");
strcat(s[i]+1,buf);
scanf("%s",buf);
l[i]=0;
if(buf[0]=='n')
l[i]=INF;
else
for(int j=0;buf[j]!='\0';j++)
l[i]=l[i]*10+buf[j]-'0';
scanf("%s",buf);
r[i]=0;
if(buf[0]=='n')
r[i]=INF;
else
for(int j=0;buf[j]!='\0';j++)
r[i]=r[i]*10+buf[j]-'0';
}
}
bool ok=1;
top=ind=0;
memset(d,0,sizeof(d));
memset(dfn,0,sizeof(dfn));
for(int i=1;i<=n&&ok;i++)
{
dfn[i]=++ind;
if(s[i][1]=='F')
{
if(d[s[i][3]-'a'])
ok=0;
d[s[i][3]-'a']++;
st[++top]=s[i][3];
stf[top]=ind;
}
else
{
d[st[top]-'a']--;
mo[stf[top]]=ind;
top--;
if(top<0)
{
ok=0;
top=0;
}
}
}
if(top>0)
ok=0;
if(!ok)
{
printf("ERR\n");
continue;
}
top=now=ans=0;
for(int i=1;i<=n;i++)
{
if(s[i][1]=='F')
{
if(l[i]<=r[i])
{
if(r[i]==INF&&l[i]!=INF)
now++;
st[++top]=(r[i]==INF&&l[i]!=INF);
ans=max(ans,now);
}
else
i=mo[i];
}
else
if(st[top--])
now--;
}
if(ans==0&&c[3]=='1')
printf("Yes\n");
else if(ans==k)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 13.83 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #2 | 13.44 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #3 | 17.92 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #4 | 25.89 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #5 | 35.59 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #6 | 21.02 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #7 | 34.87 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #8 | 61.95 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #9 | 44.28 us | 20 KB | Accepted | Score: 10 | 显示更多 |
Testcase #10 | 89.24 us | 20 KB | Accepted | Score: 10 | 显示更多 |