Cod sursa(job #1532493)

Utilizator toniobFMI - Barbalau Antonio toniob Data 21 noiembrie 2015 15:44:31
Problema 1-sir Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 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;

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

	out << a[s];

	return 0;
}