天天看点

B - Makes And The Product CodeForces - 817B (思维)

​​B - Makes And The Product CodeForces - 817B ​​(思维)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
long long Combination(int n, int m) 
{
    long long ans = 1; 
    for(int i=n; i>=(n-m+1); --i) 
        ans *= i; 
    while(m) 
        ans /= m--; 
    return ans; 
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int num[4],tot=0,tmp;
    memset(num,0,sizeof(num));
    num[tot]=1;tmp=a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]==tmp)
        {num[tot]++;}
        else
        {
            tmp=a[i];
            tot++;
            if(tot>=3) break;
            num[tot]++;
        }
        if(tot!=0&&num[0]>=3) {break;}
    }
    if(num[0]>=3)
    {
        //C(3,num[0]);
        long long ans=Combination(num[0],3);
        printf("%lld\n",ans);
    }
    else if(num[0]+num[1]>=3)
    {
        if(num[0]==1){
            //C(2,num[1])
            long long ans=Combination(num[1],2);
            printf("%lld\n",ans);
        }
        else{
            printf("%d\n",num[1]);
        }
    }
    else
    {
        printf("%d\n",num[2]);
    }
    return 0;
}