Cod sursa(job #2428945)

Utilizator alcholistuStafie Ciprian Mihai alcholistu Data 6 iunie 2019 22:39:54
Problema 1-sir Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <queue>
#include <fstream>
#include <cmath>
using namespace std;
ifstream in ("1-sir.in");
ofstream out ("1-sir.out");
int n, s, sir;
queue<int> *sol= new queue<int>(), *anotherQueue;
int main()
{
    in>>n>>s;
    sol->push(abs(s-n+1));
    if (s+n-1 < n*(n-1)/2)
        sol->push(s+n-1);
    for(int i=n-1;i>=1;i--)
    {
        anotherQueue = new queue<int>();
        while(!sol->empty())
        {
            int j = sol->front();
            sol->pop();
            anotherQueue->push(abs(j-i+1));
            if (j+i-1 < i*(i-1)/2)
                anotherQueue->push(j+i-1);
        }
        delete sol;
        sol = anotherQueue;
    }
    while(!sol->empty())
    {
        int el = sol->front();
        sol->pop();
        if (el==0)
            sir++;
    }
    out << sir;
    return 0;
}