Cod sursa(job #987378)

Utilizator cosmyoPaunel Cosmin cosmyo Data 20 august 2013 15:53:24
Problema 1-sir Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <cstdlib>
using namespace std;
const int N = 252;
const int MOD = 194767;
int d[2][N * N];
int n, s;

int main()
{
    ifstream fin("1-sir.in");
    ofstream fout("1-sir.out");
    fin >> n >> s;
    s = abs(s);
    int maxS = n * (n - 1);
    maxS /= 2;
    if(s > maxS)
    {
        fout << 0 << '\n';
    }

    int previous = 0, curr = 1;
    d[previous][0] = 1;
    for(int i = 2; i <= n; ++i)
    {

        for(int j = 0; j <= maxS; ++j)
        {
            d[curr][j] = d[previous][abs(j - (i - 1))] + d[previous][j + (i - 1)];
            while(d[curr][j] >= MOD)
            {
                d[curr][j] -= MOD;
            }
          //  fout << curr[j] << ' ';
        }
        previous ^= 1;
        curr ^= 1;

      //  fout << '\n';

    }

    fout << d[previous][s] << '\n';

    return 0;
}