Pagini recente » Cod sursa (job #531947) | Cod sursa (job #2802307) | Cod sursa (job #2685145) | Cod sursa (job #1645646) | Cod sursa (job #53472)
Cod sursa(job #53472)
#include <stdio.h>
#include <string.h>
#include <vector>
#define cmax 1024
#define mod 666313
#define pb push_back
using namespace std;
typedef pair<int,int> ii;
int c,l,tot,i,j;
int a[cmax];
vector <ii> hs[mod];
inline int hash(int x) {
return x % mod;
}
void add(int x) {
int p1 = hash(x);
for(int i = 0; i < (int)hs[p1].size(); i++)
if(hs[p1][i].first == x) {
hs[p1][i] = ii(x,hs[p1][i].second + 1);
return ;
}
hs[p1].pb(ii(x,1));
}
inline int hsh(int x) {
int p1 = hash(x);
for(int i = 0; i < (int)hs[p1].size(); i++)
if(hs[p1][i].first == x) return hs[p1][i].second;
return 0;
}
int main() {
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%d%d",&c,&l);
for(i = 0; i < c; i++) scanf("%d",&a[i]);
memset(hs,0,sizeof(hs));
for(i = 0; i < c; i++) {
for(j = i + 1; j < c; j++)
if(l - (a[i] + a[j]) >= 0)
tot += hsh(l - (a[i] + a[j]));
for(j = 0; j < i; j++)
add(a[i] + a[j]);
}
printf("%d\n",tot);
return 0;
}