Cod sursa(job #925728)

Utilizator iuli1505Parasca Iuliana iuli1505 Data 24 martie 2013 18:22:49
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<cstdio>
#include<vector>
#define H 4019
using namespace std;
int c,l,i,j,v[1025],sol,x;
vector<int>hash[H+1];
int main()
{
    freopen("oite.in","r",stdin);
    freopen("oite.out","w",stdout);
    scanf("%d%d", &c, &l);
    for(i=1;i<=c;++i)scanf("%d", &v[i]);
    for(i=1;i<c;++i)
    {
        for(j=i+1;j<=c;++j)
            if(l-v[i]-v[j]>=0)
            {
                x=(l-v[i]-v[j])%H;
                for(vector<int>::iterator it=hash[x].begin();it!=hash[x].end();++it)
                    if(*it==l-v[i]-v[j])++sol;
            }
        for(j=1;j<i;++j)
        {
            x=(v[i]+v[j])%H;
            hash[x].push_back(v[i]+v[j]);
        }

    }
    printf("%d ", sol);
    return 0;
}