Cod sursa(job #2750660)

Utilizator bent_larsenSturzu Antonio-Gabriel bent_larsen Data 12 mai 2021 18:12:07
Problema 1-sir Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <cstring>
#include <fstream>
#include <map>
#include <cmath>
#include <unordered_map>
using namespace std;

unordered_map<int> mp;
const int mod = 194767;
const int nmax = 260;

int solve(int S, int N)
{
	if(abs(S) > (N * (N - 1)) / 2)
		return 0;
	if(N == 1)
	{
		if(!S)
			return 1;
		return 0;
	}
	int index = S * nmax + N;
	if(mp.find(index) != mp.end())
		return mp[index];
	long long ans = 0;
	
	ans += solve(S - N + 1, N - 1);
	ans %= mod;
	ans += solve(S + N - 1, N - 1);
	ans %= mod;
	return mp[index] = ans;
}

int main() {
	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;
}