Pagini recente » Cod sursa (job #831785) | Cod sursa (job #1749348) | Cod sursa (job #2600340) | Cod sursa (job #123067) | Cod sursa (job #2428945)
#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;
}