Cod sursa(job #595758)

Utilizator Magnuscont cu nume gresit sau fals Magnus Data 13 iunie 2011 22:10:27
Problema Oite Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <cstdio>
#include <vector>

using namespace std;

struct sp
{
    int s1,s2,s;
};

vector <sp> h[9973];
int v[1025];

int main()
{
    int i,j,k,l,a,aux,aux2,n,sol=0;
    char ch[12000];
    sp auxstr;
    freopen("oite.in","r",stdin);
    freopen("oite.out","w",stdout);
    scanf("%d %d\n",&n,&l);
    fgets(ch,11990,stdin);
    for (i=1,j=-1;i<=n;++i)
    {
        ++j;
        while (ch[j]>='0'&&ch[j]<='9')
        {
            v[i]=v[i]*10+ch[j]-'0';
            ++j;
        }
    }
    for (i=1;i<n;++i)
        for (j=i+1;j<=n;++j)
        {
            auxstr.s1=i;
            auxstr.s2=j;
            auxstr.s=v[i]+v[j];
            h[auxstr.s%9973].push_back(auxstr);
        }
    for (i=0;i<9973;++i)
    {
        aux=h[i].size();
        a=(l-i)%9973;
        if (a<0) a+=9973;
        aux2=h[a].size();
        for (j=0;j<aux;++j)
            for (k=0;k<aux2;++k)
                if (h[i][j].s2<h[a][k].s1)
                    if (h[i][j].s+h[a][k].s==l)
                        ++sol;
    }
    printf("%d",sol);
    return 0;
}