Cod sursa(job #1226517)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 5 septembrie 2014 20:37:55
Problema 1-sir Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <cmath>
#include <fstream>

#define SMAX 256 * 256
#define Mod 194767

using namespace std;

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

int Dp[2][SMAX];
int n, s, Smax;

int main(){
    cin >> n >> s;
    s = fabs(s);
    Smax = n * (n - 1) / 2;
    if(Smax < s){
        printf("0\n");
        return 0;
    }
    Dp[1][0] = 1;
    for(int i = 2; i <= n; ++i){
        for(int j = 0; j <= Smax; ++j)
            Dp[0][j] = (Dp[1][(int)fabs(j - i + 1)] + Dp[1][j + i - 1]) % Mod;
        for(int j = 0; j <= Smax; ++j)
            Dp[1][j] = Dp[0][j];
    }
    cout << Dp[1][s];
    return 0;
}