Cod sursa(job #3220645)

Utilizator Robert_MitriRobert Mitri Robert_Mitri Data 4 aprilie 2024 15:37:31
Problema 1-sir Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
ifstream fin("1-sir.in");
ofstream fout("1-sir.out");

int n;
int s;
const int smax = 36000;
const int mod = 194767;
int d[2][smax + 5];

int main()
{
    fin>>n>>s;
    if(s<0)
        s=-s;
    if(s > smax)
    {
        fout<<0;
        return 0;
    }
    d[0][0]=1;
    int ind=1;
    for(int i = 2;i<=n;i++,ind=1-ind)
    {
        memset(d[ind],0,sizeof(d[ind]));
        for(int j = 0;j<=i*(i+1)/2;j++){
            d[ind][j] = (d[ind][j] + d[1-ind][abs(j-(i-1))] + d[1-ind][abs(j+(i-1))])%mod;
         }
    }
    fout<<d[1-ind][s];
}