Cod sursa(job #3276476)

Utilizator tudor_costinCostin Tudor tudor_costin Data 13 februarie 2025 18:54:50
Problema Oite Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>

using namespace std;
#define int long long
ifstream fin("oite.in");
ofstream fout("oite.out");
const int Nmax=1050;
int a[Nmax];
unordered_map<int,int> sume[Nmax];
unordered_map<int,int> tot;
signed main()
{
    int n,L;
    fin>>n>>L;
    for(int i=1;i<=n;i++) fin>>a[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            tot[a[i]+a[j]]++;
            sume[i][a[i]+a[j]]++;
            sume[j][a[i]+a[j]]++;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            int sum=a[i]+a[j];
            int need=L-sum;
            int cnt=tot[need]-sume[i][need]-sume[j][need];
            ///cout<<sum<<' '<<need<<' '<<cnt<<' '<<i<<' '<<j<<'\n';
            if(a[i]+a[j]==need) cnt++;
            ans+=cnt;
        }
    }
    fout<<ans/6<<'\n';
    return 0;
}