Cod sursa(job #2948721)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 28 noiembrie 2022 08:00:16
Problema 1-sir Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>

using namespace std;

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

const int NMAX = (1 << 8);
const int SMAX = 32896;
const int MOD = 194767;

int dp[2][2 * SMAX + 5], n, s;

int main(){

    cin >> n >> s;

    if(s > (n - 1) * n / 2 || s < (n - 1) * n / 2{

        cout << 0;
        return 0;

    }

    dp[1][SMAX] = 1;

    int curr = 0;
    int ant = 1;
    for(int i = 2; i <= n; i++){

        for(int j = -SMAX; j <= SMAX; j++){

            if(j + i <= SMAX){

                dp[curr][j + i + SMAX] += dp[ant][j + SMAX];
                dp[curr][j + i + SMAX] %= MOD;

            }

            if(j - i >= -SMAX){

                dp[curr][j - i + SMAX] += dp[ant][j + SMAX];
                dp[curr][j - i + SMAX] %= MOD;

            }

        }

        curr++;
        ant++;

        curr %= 2;
        ant %= 2;

    }

    cout << dp[ant][s + SMAX];

    return 0;
}