Cod sursa(job #2750653)

Utilizator bent_larsenSturzu Antonio-Gabriel bent_larsen Data 12 mai 2021 17:57:55
Problema 1-sir Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

const int smax = 80000;
const int dep = 40000;
const int nmax = 260;
int memo[smax][nmax];
const int mod = 194767;

int solve(int S, int N)
{
	if(S + dep >= smax)
		return 0;
	if(N == 1)
	{
		if(!S)
			return 1;
		return 0;
	}
	if(memo[S + dep][N] != -1)
		return memo[S + dep][N];
	long long ans = 0;
	
	ans += solve(S - N + 1, N - 1);
	ans %= mod;
	ans += solve(S + N - 1, N - 1);
	ans %= mod;
	return memo[S + dep][N] = ans;
}

int main() {
	memset(memo, -1, sizeof(memo));
	ifstream in("1-sir.in");
	ofstream out("1-sir.out");
	int N, S;
	
	in >> N >> S;
	out << solve(S, N) << "\n";
	in.close();
	out.close();
	return 0;
}