12028 - A Gift from the Setter

All about problems in Volume 120. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
unaisah
New poster
Posts: 1
Joined: Tue Jul 26, 2011 12:29 am

12028 - A Gift from the Setter

Post by unaisah » Thu Jul 28, 2011 11:56 pm

why WA ? i think my algorithm is not working properly.Any hints ??
Thanks in advance !

Code: Select all

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
using namespace std;


long long  n,k,c,t;
long long  y=0,xx,temp;
long long  sum (long long  aa[],long long  nn)
{
	long long  sum=0,sum2=0;
	int i;
	long count=1;
	for(i=1;i<nn;i++)
	{
		sum2+=aa[i];
		temp=y-sum2;
		temp=abs(temp-(aa[i]*(nn-count)));
		sum+=temp;	
		count++;
	}

	return sum;
}

int main()
{

	int li,test,j;
	scanf("%d",&test);
	for(j=1;j<=test;j++)
	{
		long long a[100099];
		y=0;
		scanf("%lld%lld%lld%lld",&k,&c,&n,&t);
		y=t;
		a[1]=t;
		for(li=2;li<=n;li++)
		{
			a[li]=(k*a[li-1]+c)%1000007;
		
			y+=a[li];
		}
		xx=sum(a,n);
		if(j<test)
		printf("Case %d: %lld\n",j,xx);
		else
			printf("Case %d: %lld",j,xx);
		
	}

	return 0;
}

amin__
New poster
Posts: 10
Joined: Thu Jul 01, 2010 10:44 am

Re: 12028

Post by amin__ » Sat Jul 30, 2011 2:44 pm

I did not understand your code completely..but I think there is a problem in the for loop in sum routine..

I randomly choose two input and they fail in your solution...inputs are:
2
10 10 10 12
10 10 10 100

output should be
Case 1: 4639073
Case 2: 5240402

hope these will help :)

robot
New poster
Posts: 29
Joined: Sun May 24, 2009 8:39 pm

Re: 12028

Post by robot » Mon Aug 22, 2011 2:18 pm

Hi unaisah ..
you have a simple mistake...
A sort function require....According ur code.....
a[0]=t;
for(li=1;li<n;li++)
{
a[li]=(k*a[li-1]+c)%1000007;
y+=a[li];
}
sort(&a[0],&a[n]);
xx=sum(a,n);
printf("Case %d: %lld\n",j,xx);

In Sum funtion:
for(i=0;i<nn;i++)
{

}
return sum

I hope u will get Accepted......... :)
ASU(SUST)

Post Reply

Return to “Volume 120 (12000-12099)”