11059 - Maximum Product

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

Moderator: Board moderators

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi »

why WA ??? :(

Code: Select all

CODE DELETED AFTER AC :)
Last edited by abhi on Wed Jun 20, 2007 4:41 am, edited 1 time in total.
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post 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." ?
abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi »

my program outputs the following for ur test case

Code: Select all

Case #1: The maximum product is 0.
abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi »

never mind.
found my error and got AC :)
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr »

Code: Select all

removed
Last edited by lnr on Sat Sep 01, 2007 11:34 am, edited 4 times in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Use 'long long' instead of 'long double'.
Ami ekhono shopno dekhi...
HomePage
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr »

Code: Select all

changed
Last edited by lnr on Sun Jul 15, 2007 6:20 pm, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Post by lnr »

Code: Select all


   Changed    

Last edited by lnr on Wed Aug 01, 2007 4:25 pm, edited 1 time in total.
andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post 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.
Now I lay me down to sleep...
my profile
andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post 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;
}
Now I lay me down to sleep...
my profile
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

hi...
fix this...

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

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

>> but urs code outputs 1..
andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post 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
Now I lay me down to sleep...
my profile
dipaly
New poster
Posts: 20
Joined: Tue Sep 19, 2006 6:18 pm
Location: bangladesh
Contact:

wa :(

Post 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:
Last edited by dipaly on Fri Aug 31, 2007 4:12 pm, edited 1 time in total.
everything is so hard to me
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
Post Reply

Return to “Volume 110 (11000-11099)”