Pagini recente » Cod sursa (job #674851) | Cod sursa (job #1220700) | Cod sursa (job #2598986) | Cod sursa (job #695899) | Cod sursa (job #625410)
Cod sursa(job #625410)
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
struct str{int x,y;};
struct cmp_str{bool operator()(str x,str y){return x.x<y.x;};};
inline str mp(int x,int y){str aux;aux.x=x;aux.y=y;return aux;}
char v[1025];
int n,t,i,j,p,v2[1025],ok,pos=0;
str eval(int lvl)
{
vector<str> s;
vector <str>::iterator it;
str r,aux;
if(lvl==0)
{
for(s.push_back(eval(lvl+1));v[pos]=='#';)
++pos,s.push_back(eval(lvl+1));
sort(s.begin(),s.end(),cmp_str());
r=s[0];
for(it=s.begin();it!=s.end();++it)
if(it->x!=(it-1)->y+1)
ok=0;
else
r.y=it->y;
return r;
}
if(lvl==1)
{
for(r=eval(lvl+1);v[pos]=='>';)
{
++pos;
if(r.y!=(aux=eval(lvl+1)).x-1)
ok=0;
r.y=aux.y;
}
return r;
}
if(v[pos]=='(')
{
++pos;
r=eval(0);
++pos;
return r;
}
int x=0;
while(v[pos]>='0'&&v[pos]<='9')
x=(x<<3)+(x<<1)+v[pos++]-'0';
return mp(v2[x],v2[x]);
}
int main()
{
freopen("episoade.in","r",stdin);
freopen("episoade.out","w",stdout);
fgets(v,sizeof(v),stdin);
scanf("%d%d",&t,&n);
for(;t;--t)
{
pos=0;
for(i=1;i<=n;++i)
scanf("%d",&j);
v2[j]=i;
ok=1;
eval(0);
printf("%d\n",ok);
}
return 0;
}