Cod sursa(job #2913739)

Utilizator vlad2009Vlad Tutunaru vlad2009 Data 16 iulie 2022 17:22:40
Problema 1-sir Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <cmath>
#define int long long

using namespace std;

const int MAX_SUM = (256 * 257) / 2;
const int MOD = 194767;
int dp[2][MAX_SUM + 1];
int n, s;

signed main() {
    ifstream fin("1-sir.in");
    ofstream fout("1-sir.out");
    fin >> n >> s;
    int maxsum = n * (n - 1) / 2;
    if (maxsum < abs(s)) {
        fout << "0";
        return 0;
    }
    dp[1][0] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i * (i + 1); j++) {
            dp[(i & 1) ^ 1][j] = (dp[i & 1][abs(j + i)] + dp[i & 1][abs(j - i)]) % MOD;
        }
    }
    fout << dp[n & 1][abs(s)];
    return 0;
}