Swagath's blog

By Swagath, 11 years ago, In English

I have been trying this problem http://www.spoj.com/problems/ESY/.. SPOJ/ESY

pls help me what cases i'm missing... pls....

#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
	int n;
	while(scanf("%d",&n)!=-1){
		int a[n];
		int ones=0;
		int ans=1;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			a[i]*=(a[i]<0)?-1:1;
			if(a[i]>1)
				ans*=a[i];
			else if(a[i]==1)
				ones++;
		}
		//cout<<ans<<" "<<ones<<endl;
		if(ans==1)
			ans=0;
		int k=ones,l;
		if(ones>3)
		{
			k=ones/2;
			l=ones-k;
			k=k*l;
		}	
		if(ans>0&&k>1)
			ans*=k;
		else
			ans+=k;
		ans*=-1;
		cout<<ans<<endl;
			
	}
	return 0;
}
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

This problem is not so easy. I think it is DP.