Cod sursa(job #2398335)

Utilizator Anakin1001George Giorgiu Gica Anakin1001 Data 5 aprilie 2019 12:50:09
Problema Oite Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <climits>
#include <vector>
#include <cstring>
#define mod 10007
using namespace std;
ifstream f("oite.in");
ofstream g("oite.out");
vector <pair <long long,int> >  v[mod+1];
int sol,i,j,r,a,x[1025],n,L;
long long S;
int caut(int x){
    for(int i=0;i<v[r].size();i++)
        if(v[r][i].first==x)
            return i;
    return -1;
}
int main()
{   f>>n>>L;
    for(i=1;i<=n;i++)
        f>>x[i];
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            S=x[i]+x[j];
            r=(L-S)%mod;
            a=caut(L-S);
            if(a!=-1)
                sol+=v[r][a].second;
        }
        for(j=1;j<=i-1;j++){
            S=x[i]+x[j];
            r=S%mod;
            a=caut(S);
            if(a!=-1)
                v[r][a].second++;
            else
                v[r].push_back(make_pair(S,1));
        }
    }
    g<<sol;
    return 0;
}