Cod sursa(job #7001)

Utilizator mastermageSchneider Stefan mastermage Data 21 ianuarie 2007 11:38:26
Problema 1-sir Scor 10
Compilator cpp Status done
Runda preONI 2007, Runda 1, Clasele 11-12 Marime 0.81 kb
#include <stdio.h>

#define maxN (100)
#define mS (20000)
#define maxS (mS+(maxN*4))
#define jS (mS/2)
#define modul 194767

int n, s, res;

int din[maxN][maxS];

int& di(const int&a,const int&b){
	return (((din+maxN/2)[a])+maxS/2)[b];
}

void inputFunc(){
	FILE*fi=fopen("1-sir.in","r");
	fscanf(fi,"%d %d",&n,&s);
	fclose(fi);
}

void outputFunc(){
	FILE*fi=fopen("1-sir.out","w");
	fprintf(fi,"%d",res%modul);
	fclose(fi);
}

int main(){
	inputFunc();
	if(s<-35000 || s>35000){res=0;outputFunc();return 0;}
	
	di(0,0)=1;
	for(int i=1;i<n;i++){
		for(int j=-i;j<=i;j+=2){
			for(int k=-jS;k<=jS;k++){
				int x=di(j-1,k-j) + di(j+1,k-j); 
				while(x>=modul)x-=modul;
				di(j,k)=x;
			}
		}
	}
	
	for(int j=-n+1; j<=n-1; j+=2)
		res+=di(j,s);
	
	outputFunc();
	return 0;
}