Page 3 of 7

Posted: Tue Jun 19, 2007 7:52 pm
by abhi
why WA ??? :(

Code: Select all

CODE DELETED AFTER AC :)

Posted: Tue Jun 19, 2007 8:03 pm
by Spykaj
1
-5

Why unsigned ? Are you read this line: "If you cannot find a positive sequence, you should consider 0 as the value of the maximum product." ?

Posted: Wed Jun 20, 2007 4:31 am
by abhi
my program outputs the following for ur test case

Code: Select all

Case #1: The maximum product is 0.

Posted: Wed Jun 20, 2007 4:41 am
by abhi
never mind.
found my error and got AC :)

Posted: Wed Jul 04, 2007 10:08 am
by lnr

Code: Select all

removed

Posted: Wed Jul 04, 2007 5:54 pm
by Jan
Use 'long long' instead of 'long double'.

Posted: Sat Jul 14, 2007 6:06 pm
by lnr

Code: Select all

changed

Posted: Sat Jul 14, 2007 10:40 pm
by Jan
Try the cases.

Input:

Code: Select all

16
-3 -2 3 4 8 8 -1 -1 7 -4 9 3 2 -5 10 -2

12
4 5 5 3 0 7 -3 0 10 2 4 -1

17
10 2 -10 2 10 5 -8 8 -6 -7 7 0 -5 -2 6 8 5
Output:

Code: Select all

Case #1: The maximum product is 348364800.

Case #2: The maximum product is 300.

Case #3: The maximum product is 376320000.
Hope these help.

Posted: Sun Jul 15, 2007 6:25 pm
by lnr

Code: Select all


   Changed    


Posted: Tue Jul 17, 2007 9:52 pm
by andysoft
What's must be the printf format? "%d", "%ld", "%lld" ???
My program is ok, if I look at my answer in Borland's c++ debugger, answer is ok, but when answer is too big (int64 size), values in debugger and printed in the console DIFFER. I guess it is because of output format.

Posted: Tue Jul 17, 2007 9:58 pm
by andysoft
this is my code. strange that even when I translated it to pas (where it prints int64's ok for sure) it gives WA. Maybe look what's wrong..

Code: Select all

#include <cstdlib>
#include <iostream>
#include <cstdio>

using namespace std;

int main(int argc, char* argv[]) {
	int i,j,n,a[20],ci;
	long long int b[20],max;
	ci = 0;
	while (cin >> n) {
		ci++;
		b[0] = 1;
		for (i=1; i<=n; i++) {
			cin >> a[i];
			if (b[i-1] != 0)
			b[i] = a[i]*b[i-1];
			else
			b[i] = a[i];
		}
		getchar ();
		max = 0;
		for (i=1; i<=n; i++)
			for (j=i; j<=n; j++)
				if (b[i-1] != 0)
				if (b[j]/b[i-1] > max)
					max = b[j]/b[i-1];
		cout << "Case #" << ci << ": The maximum product is ";
		printf ("%lld.\n\n",max);

	}
	return 0;
}

Posted: Tue Jul 17, 2007 11:35 pm
by ayeshapakhi
hi...
fix this...

input.........
3
-1 0 -1

output.......
Case #1: The maximum product is 0.

>> but urs code outputs 1..

Posted: Wed Jul 18, 2007 12:23 pm
by andysoft
Thank you for the test case, ayeshapakhi!
I thought my prog is working fine with zeros and I was concentrating on other test cases, but all they passed.
Now I got AC @ 0.002s

wa :(

Posted: Thu Aug 30, 2007 6:31 pm
by dipaly
hi .........i get wa on this prob.. . i use O(n) algo..

can any one help me to find the mistake
sorry 4 submitting code
deleted
:oops:

Posted: Thu Aug 30, 2007 9:59 pm
by Jan
Check your code again. You are using

Code: Select all

long tem  = pp*arr[i];
Isn't it should be

Code: Select all

long long tem  = pp*arr[i];
Hope it helps.