Cod sursa(job #2446175)

Utilizator PetrescuAlexandru Petrescu Petrescu Data 7 august 2019 13:31:58
Problema 1-sir Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <iostream>
#define MODULO 194767
#define MAX ((255 * 256) / 2)

using namespace std;

int dp[MAX];
int main()
{
    int n, s, i, j;

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

    fin >> n >> s;

    if(s < 0)s = -s;

    s = n * (n - 1) / 2 - s;

    if(s < 0 || s % 2 == 1)
    {
        fout << 0;
        return 0;
    }

    s /= 2;

    dp[0] = 1;
    for(i = 1; i < n; i++)
        for(j = s - i; j >= 0; j--)
            dp[j + i] = (dp[j + i] + dp[j]) % MODULO;

    fout << dp[s];

    fin.close();
    fout.close();

    return 0;
}