Cod sursa(job #1532515)

Utilizator toniobFMI - Barbalau Antonio toniob Data 21 noiembrie 2015 15:47:28
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream in("1-sir.in");
ofstream out("1-sir.out");

int n, s;
const int modulo = 194767;
const int jumate = 256 / 2 * 257;

int main() {

	in >> n >> s;

	int smax = (n-1)*n / 2;
	s = s < 0 ? -s : s;
	s = smax - s;
	int a[s + 1];
	for (int i = 0; i <= s; a[i++] = 0);
	a[0] = 1;

	int x;
	for (int i = 1; i < n; ++i) {
		for (int j = s; j >= 0; --j) {
			if (a[j]) {
				x = j + 2 * i;
				if (x <= s) {
					a[x] += a[j];
					if (a[x] > modulo) a[x] -= modulo;
				}
			}
		}
	}

	out << a[s];

	return 0;
}