AtCoder C - Make a Rectangle
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
typedef long long LL;
typedef vector<LL>vll;
typedef map<LL, LL>mplli;
vll v;
mplli mp;
set<LL>st;
int main()
{
fast;
int N;
cin >> N;
int i;
for(i=0; i<N; i++)
{
LL x;
cin >> x;
st.insert(x);
mp[x]++;
}
set<LL>::iterator it;
for(it=st.begin(); it!=st.end(); it++)
{
// cout << *it << "; ";
v.push_back(*it);
}
int len = v.size();
LL mul = 1;
int cnt = 0;
if(mp[v[len-1]] >= 4) cout << v[len-1] * v[len-1] << "\n";
else
{
cnt = 0;
mul = 1;
for(i=len-1; i>=0; i--)
{
if(mp[v[i]] >= 2)
{
cnt+=1;
mul *= v[i];
}
if(cnt == 2) break;
}
if(cnt == 2) cout << mul << "\n";
else cout << "0\n";
}
return 0;
}
using namespace std;
#define fast ios_base::sync_with_stdio(0)
typedef long long LL;
typedef vector<LL>vll;
typedef map<LL, LL>mplli;
vll v;
mplli mp;
set<LL>st;
int main()
{
fast;
int N;
cin >> N;
int i;
for(i=0; i<N; i++)
{
LL x;
cin >> x;
st.insert(x);
mp[x]++;
}
set<LL>::iterator it;
for(it=st.begin(); it!=st.end(); it++)
{
// cout << *it << "; ";
v.push_back(*it);
}
int len = v.size();
LL mul = 1;
int cnt = 0;
if(mp[v[len-1]] >= 4) cout << v[len-1] * v[len-1] << "\n";
else
{
cnt = 0;
mul = 1;
for(i=len-1; i>=0; i--)
{
if(mp[v[i]] >= 2)
{
cnt+=1;
mul *= v[i];
}
if(cnt == 2) break;
}
if(cnt == 2) cout << mul << "\n";
else cout << "0\n";
}
return 0;
}
Comments
Post a Comment