Cod sursa(job #735247)

Utilizator robertpoeRobert Poenaru robertpoe Data 15 aprilie 2012 22:06:15
Problema Diviz Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include<stdio.h>
#include<string.h>
#define maxn (1<<8)
long k,a,b,cif,max,i,sol,l2,l,l3,j,aux,aux2;
int N[maxn][20],V[10][maxn][maxn];
char s[maxn];
int main() 
{
	freopen("diviz.in", "r", stdin);
	freopen("diviz.out", "w", stdout);
	scanf("%ld %ld %ld", &k, &a, &b);
	scanf("%s", s);
	long n=strlen(s);
	for(cif=0;cif<=9;++cif)	
	{
		max=n+1;
		for(i=n;i>=0;--i) 
		{
			N[i][cif]=max;
			if(s[i]-'0'==cif)
				max=i;
		}
		if(max!=n+1&&cif!=0)
			V[1][max][cif%k]=1;
	}
	sol=0;
	for(l2=1;l2<=b;++l2) 
	{
		l=l2%2;
		l3=(l+1)%2;
		for(i=0;i<n;++i)
		{
			for(j=0;j<k;++j)
			{
				if(V[l][i][j]==0) 
					continue;
				if(l2>=a&&l2<=b&&j==0)
				{
					sol+=V[l][i][j];
					if(sol>=30103) 
						sol-=30103;
				}
				if(l==b) 
					continue;
				for(cif=0;cif<=9;++cif) 
				{
					aux=N[i][cif];
					if(aux==n+1)
						continue;
					aux2=j*10+cif;
					while(aux2>=k)
						aux2-=k;
					V[l3][aux][aux2]+=V[l][i][j];
					if(V[l3][aux][aux2]>=30103)
						V[l3][aux][aux2]-=30103;
				}
				V[l][i][j]=0;
			}
		}
	}
	printf("%ld\n", sol);
	return 0;
}