Cod sursa(job #253763)

Utilizator taloibogdanTaloi Bogdan Cristian taloibogdan Data 6 februarie 2009 12:14:32
Problema Episoade Scor 20
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 1 Marime 1.1 kb
#include<stdio.h>
#include<string.h>
long l,i,j,p,jj,x[105][105],h[105],n,m,f,a,k;
char exp[1005];
int main()
{
 freopen("episoade.in","r",stdin);
 freopen("episoade.out","w",stdout);
 gets(exp);
 l=strlen(exp);
// gc=0;
 for(i=0;i<l;++i)
    {
    /* if(exp[i]=='('){++gc;igr[++g]=i+1;}
     if(exp[i]>0&&exp[i]<=9)unr[++dr]=(long)exp[i]-(long)'0';*/
     if(exp[i]=='>')
       for(j=i-1;j>=0;--j)

	  {if(exp[j]==')')++p;
	   if(exp[j]=='(')--p;
	   if((p==0&&(exp[j]=='#'||exp[j]=='>'))||p<0)break;

	   if(exp[j]>'0'&&exp[j]<='9')
	     for(jj=i+1;jj<l;++jj)

		{if(exp[jj]=='(')++p;
		 if(exp[jj]==')')--p;
		 if((p==0&&(exp[jj]=='#'||exp[jj]=='>'))||p<0)break;

		 if(exp[jj]>'0'&&exp[jj]<='9')
		   x[(long)exp[jj]-(long)'0'][++x[(long)exp[jj]-(long)'0'][0]]=(long)exp[j]-(long)'0';
		}
	  }
    }
 scanf("%ld%ld",&n,&m);
 for(i=1;i<=n;++i)
    {
     f=1;
     memset(h,999,sizeof(h));
     for(j=1;j<=m;++j)
	{scanf("%ld",&a);
	 if(f)
	 {h[a]=j;
	  for(k=1;k<=x[a][0];++k)
	     {if(h[x[a][k]]<j-x[a][0]){f=0;break;}}}

	}
     printf("%ld\n",f);
    }
 return 0;
}