Cod sursa(job #2104989)

Utilizator BaldurCronos Baldur Data 12 ianuarie 2018 14:46:29
Problema 1-sir Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
#define N 256
#define MOD 194767
using namespace std;
ifstream in ("1-sir.in");
ofstream out("1-sir.out");
int dp[2][N * N + 1];

int abs(int x) {
        return (x < 0 ? -x : x);
}

int main() {
        int n, s, mx, line = 1;
        in >> n >> s;
        mx = n * (n + 1) / 2;

        if (s > mx || s < -mx) {
                cout << 0;
                return 0;
        }

        dp[0][0] = 1;
        for (int i = 2; i <= n; i++) {
                for (int j = 0; j <= mx; j++) {
                        dp[line][j] = (dp[1 - line][abs(j - (i - 1))] + dp[1 - line][abs(j + (i - 1))]) % MOD;
                }
                line = 1 - line;
        }

        out << dp[1 - line][s];
        return 0;
}