Cod sursa(job #1653689)

Utilizator bogdanboboc97Bogdan Boboc bogdanboboc97 Data 16 martie 2016 13:59:36
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <map>
#define pb push_back
#define mp make_pair
#define INF numeric_limits<int>::max()
#define bit(x) (-x)&x
#define int64 long long
using namespace std;
ifstream in("oite.in");
ofstream out("oite.out");
#define mod 666013
int a[1025],n,sum;
vector< vector< pair<int,int> > > h(mod);
void ins(int x)
{
    int c=x%mod;
    for(int i=0;i<(int)h[c].size();i++)
    if(h[c][i].first==x)
    {
        h[c][i].second++;
        return;
    }
    h[c].pb(mp(x,1));
}
int cnt(int x)
{
    if(x<0)
        return 0;
    int c=x%mod;
    for(int i=0;i<(int)h[c].size();i++)
    if(h[c][i].first==x)
        return h[c][i].second;
    return 0;
}
int main()
{
    in>>n>>sum;
    for(int i=1;i<=n;i++)
        in>>a[i];
    int sol=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
            sol+=cnt(sum-a[i]-a[j]);
        for(int j=i-1;j>=1;j--)
            ins(a[i]+a[j]);
    }
    out<<sol<<'\n';
    return 0;
}