Cod sursa(job #479223)

Utilizator Addy.Adrian Draghici Addy. Data 23 august 2010 13:10:15
Problema 1-sir Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <cstdio>

#define SMAX 1 << 16
#define MOD 194767

int A[SMAX], B[SMAX], n, i, j, x, y, S;

int main () {
	
	freopen ("1-sir.in", "r", stdin);
	freopen ("1-sir.out", "w", stdout);
	
	scanf ("%d %d", &n, &S);
	
	if (S > n * (n-1) / 2 || S < - n * (n-1) / 2)
		printf ("0");
	else {
		A[0] = 1;
		for (i = 2; i <=  n; i++) {
			for (j = 0; j <= n * (n-1) / 2; j++) {
				x = j - (n-i+1); if (x < 0) x = -x;
				B[j] += A[x];
				y = j + (n-i+1); if (y < 0) y = -y;
				B[j] = (B[j] + A[y]) % MOD;
			}
			
			for (j = 0; j <= n * (n-1) / 2; j++)
				A[j] = B[j], B[j] = 0;
		}
		
		if (S >= 0)
			printf ("%d", A[S]);
		else
			printf ("%d", A[-S]);
	}
	
	return 0;
}