Cod sursa(job #2396085)

Utilizator alex2209alexPavel Alexandru alex2209alex Data 3 aprilie 2019 10:53:56
Problema Diamant Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
using namespace std;
ifstream f("diamant.in");
ofstream g("diamant.out");
int_fast32_t n,m,i,j,k,x,s,d[2][100001],t,s2,mod=10000,y;
int_fast32_t invers(int_fast32_t x)
{
	if(x<0)
		return 45000-x;
	else
		return x;
}
int main()
{
	f>>n>>m>>x;
	for(i=1; i<=n; i++)
		for(j=1; j<=m; j++)
		{
			s+=i*j;
		}
	if(x>s || x<-s)
		g<<0;
	else
	{
		t=1;
		d[0][0]=1;
		s2=0;
		for(i=1; i<=n; i++)
			for(j=1; j<=m; j++)
			{
				s2+=i*j;
				for(k=-s2; k<=s2; k++)
				{
					y=invers(k);
					d[t][y]=d[1-t][y];
					if(k-i*j>=-s)
						d[t][y]=(d[t][y]+d[1-t][invers(k-i*j)])%mod;
					if(k+i*j<=s)
						d[t][y]=(d[t][y]+d[1-t][invers(k+i*j)])%mod;
				}
				t=1-t;
			}
		g<<d[1-t][invers(x)];
	}
}