Page 6 of 7
Re: 11059 - Maximum Product
Posted: Mon Dec 10, 2012 12:44 pm
by gr81
what would be the output for the following test case.
2
-1 -2
6
2 5 -1 2 -3 0
do i need to consider the -ve number, if I go with problem statement, output for 1st test case should be 0 and for 2nd test case should 10, but UVA toolkit gives different output. please suggest.
Re: 11059 - Maximum Product
Posted: Mon Dec 10, 2012 10:08 pm
by brianfry713
Code: Select all
Case #1: The maximum product is 2.
Case #2: The maximum product is 60.
Re: 11059 - Maximum Product
Posted: Mon Dec 10, 2012 10:12 pm
by brianfry713
Input:
Code: Select all
18
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
AC output:
Code: Select all
Case #1: The maximum product is 1000000000000000000.
Re: 11059 - Maximum Product
Posted: Tue Dec 11, 2012 7:08 am
by gr81
thanks brian, is there any O(n) solution for that, can we solve this problem using modified Kadane algorithm...
Re: 11059 - Maximum Product
Posted: Tue Dec 11, 2012 11:03 pm
by brianfry713
11059 - Maximum Product
Posted: Thu Jan 10, 2013 12:04 am
by armankashef
hi
Why I getting WA
Code: Select all
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <stdio.h>
using namespace std ;
long long f( int m[18] , int n )
{
long long i , j, t , s = 1 , mx = 0 ;
for ( i = 2 ; i < 262144 ; i++ )
{
t = 0 ;
s = 1 ;
for( j = 17 ; j >= 0 ; j-- )
{
t = ( i >> j ) - t * 2 ;
if( t )
s *= m[j] ;
}
mx = max( mx , s ) ;
}
return mx ;
}
int mat[19];
int main()
{
int n , i , j = 1 ;
while( cin >> n )
{
memset( mat , 0 , sizeof ( mat ) ) ;
for( i = 0 ; i < n ; i++ )
{
cin >> mat[i] ;
}
cout << "Case #" << j << ": The maximum product is " << f( mat , n ) << "." << endl << endl ;
j++ ;
}
return 0 ;
}
help me plz
Re: 11059 - Maximum Product
Posted: Thu Jan 10, 2013 11:06 pm
by brianfry713
Input
AC output:
Code: Select all
Case #1: The maximum product is 2.
Re: 11059 - Maximum Product
Posted: Fri Jan 11, 2013 11:17 pm
by armankashef
what's your mean ?
( for that test case my program's output is 4 )
Re: 11059 - Maximum Product
Posted: Sat Jan 12, 2013 6:21 pm
by brianfry713
Given a sequence of integers S = {S1, S2, ..., Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S.
Your code is wrong, the correct output is 2.
Re: 11059 - Maximum Product
Posted: Sun Jan 13, 2013 4:07 pm
by armankashef
Re: 11059 - Maximum Product
Posted: Sun Jan 13, 2013 9:49 pm
by brianfry713
input
Code: Select all
18
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
AC output:
Code: Select all
Case #1: The maximum product is 1000000000000000000.
Re: 11059 - Maximum Product
Posted: Mon Jan 14, 2013 11:16 am
by armankashef
Thank you
accepted
Re: 11059 - Maximum Product
Posted: Sun Mar 17, 2013 6:55 am
by Nut_Boltu
I m getting WA. plz Help.
Code: Select all
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long long n,product,arr[25],MaxP;
int count=1;
while(cin>>n)
{
for(int i=0;i<n;i++) cin>>arr[i];
MaxP=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
product = 1;
for(int k=i;k<=j;k++)
{
product*=arr[k];
if(product>MaxP) MaxP = product;
}
}
}
cout<<"Case #"<<count++<<": The maximum product is "<<MaxP<<"."<<endl;
}
return 0;
}
11059 - Maximum Product
Posted: Tue Mar 19, 2013 7:12 pm
by Nut_Boltu
Why m i getting WA? plz anyone reply.
Code: Select all
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long long n,product,arr[25],MaxP;
int count=1;
while(cin>>n)
{
for(int i=0;i<n;i++) cin>>arr[i];
MaxP=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
product = 1;
for(int k=i;k<=j;k++)
{
product*=arr[k];
if(product>MaxP) MaxP = product;
}
}
}
cout<<"Case #"<<count++<<": The maximum product is "<<MaxP<<"."<<endl;
}
return 0;
}
Re: 11059 - Maximum Product
Posted: Tue Mar 19, 2013 8:30 pm
by brianfry713
After each test case you must print a blank line.