Cod sursa(job #2409871)

Utilizator armandpredaPreda Armand armandpreda Data 19 aprilie 2019 15:03:29
Problema 1-sir Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <cmath>

using namespace std;

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

const int LIM = 260, MOD = 194767;
int n, s, dp[2][LIM * LIM];
bool ant = 0, cur = 1;

int main()
{
    cin >> n >> s; s = abs(s);

    if (s > (n + 1) * n / 2)
    {
        cout << 0;
        return 0;
    }

    dp[ant][0] = 1;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 0; j <= i * (i - 1) / 2; ++j)
            dp[cur][j] = (1ll * dp[ant][(int)abs(j - (i - 1))] + dp[ant][j + (i - 1)]) % MOD;
        ant = !ant;
        cur = !cur;
    }
    cout << dp[ant][s];
    return 0;
}