(AGC)C - Make a Rectangle

C - Make a Rectangle


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

We have N sticks with negligible thickness. The length of the i-th stick is Ai.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

Constraints

  • 4N105
  • 1Ai109
  • Ai is an integer.

Input

Input is given from Standard Input in the following format:

N
A1 A2 ... AN

Output

Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.


Sample Input 1

Copy
6
3 1 2 4 2 1

Sample Output 1

Copy
2

1×2 rectangle can be formed.


Sample Input 2

Copy
4
1 2 3 4

Sample Output 2

Copy
0

No rectangle can be formed.


Sample Input 3

Copy
10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

Copy
20
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
struct node{
	int id;
	int nu;
}b[maxn];
int n;
int a[maxn];
int main()
{
	int i,j;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		i=n-1;
		int cnt=0;
		int num=0;
		while(i>=0)
		{
			num++;
			for(j=i;j>=0;j--)
			{
				if(a[j]!=a[i])
					break;
				else cnt++;
			}
			b[num].id=a[i];
			b[num].nu=cnt;
			cnt=0;
			i=j;
		}
		int c[2];
		int s=0;
		c[0]=-1;
		c[1]=-1;
	//	for(i=1;i<=num;i++)
		//	cout<<b[i].nu<<endl;
		for(i=1;i<=num;i++)
		{
			//	cout<<"!"<<endl;	
			 if(b[i].nu>=4)
			{
				
				c[s]=b[i].id;
				s++;
				if(s>=2) break;
				c[s]=b[i].id;
				break;
			}
			if(b[i].nu>=2)
			{
			//	cout<<"!"<<endl;
			   c[s]=b[i].id;
			   	s++;
			}
		
			if(s>=2) break;
		}
		//cout<<c[0]<<" "<<c[1]<<endl;
		if(c[0]==-1||c[1]==-1) 
		printf("0\n");
		else printf("%lld\n",1ll*c[0]*c[1]);
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值