Cod sursa(job #466770)

Utilizator AndreyPAndrei Poenaru AndreyP Data 27 iunie 2010 14:35:19
Problema Congr Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, clasele X-XII, Ziua 1 Marime 0.75 kb
#include <cstdio>
#define P 310

int p,n;
int a[P];
int b[P][P];

inline void citire()
{
	scanf("%d",&p);
	n=(p<<1)-1;
	for(int i=1; i<=n; ++i)
	{
		scanf("%d",&a[i]);
		a[i]%=p;
	}
}

inline void rezolva()
{
	int x;
	for(int i=1; i<=n; ++i)
	{
		for(int j=p; j>1; --j)
		{
			for(int t=0; t<p; ++t)
			{
				x=t-a[i];
				if(x<0)
					x+=p;
				if(b[i-1][x])
					b[i][t]=i;
			}
		}
		b[1][a[i]]=i;
	}
}

inline void scrie()
{
	int x=0;
	for(int i=p; i>0; --i)
	{
		if(i==1)
			printf("%d\n",b[i][x]);
		else
			printf("%d ",b[i][x]);
		x-=a[b[i][x]];
		if(x<0)
			x+=p;
	}
}

int main()
{
	freopen("congr.in","r",stdin);
	freopen("congr.out","w",stdout);
	
	citire();
	rezolva();
	scrie();
	
	return 0;
}