Cod sursa(job #1216457)

Utilizator ZenusTudor Costin Razvan Zenus Data 4 august 2014 17:02:06
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define MOD 60013
#define MP make_pair
#define PB push_back
#define NMAX 1030

vector < pair < long long , short > > H[MOD];
vector < pair < long long , short > > :: iterator e;
int i,j,N,L,ans,X;
int V[NMAX];
long long f;

int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);

scanf("%d%d",&N,&L);

for (i=1;i<=N;++i)
{
    scanf("%d",&X);
    if (X<=L) V[++V[0]]=X;
}
N=V[0];

sort(V+1,V+N+1);

for (i=1;i<=N;++i)
for (j=i+1;j<=N;++j)
{
    if (V[i]+V[j]<=L-2*V[1])
    H[(V[i]+V[j])%MOD].PB(MP(V[i]+V[j],j));
}

for (i=1;i<=N && V[i]+V[1]<=L/2;++i)
for (j=i+1;j<=N && V[i]+V[j]<=L;++j)
{
    f=(L-V[i]-V[j])%MOD;

    for (e=H[f].begin();e!=H[f].end();++e)
    if (i>(*e).second && (*e).first+V[i]+V[j]==L)
    ++ans;
}

printf("%d\n",ans);

return 0;
}