Cod sursa(job #1474566)

Utilizator theprdvtheprdv theprdv Data 22 august 2015 12:41:18
Problema Trie Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.2 kb
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <ctime>
#define foreach(G) for(hash_line *it = (G); it; it = it->next)
#define MOD 99013
#define hash(x) ( MOD * ((double)(0.618034 * (x))  - (int)(0.618034 * (x))) )
#define list (key % MOD)
#define MAXN 1001

using namespace std;

struct hash_line{
	int val;
	short int l, r;
	hash_line *next;
} *Hash[MOD];

int N, v[MAXN], Sv[MAXN], ans;
unsigned int S;

inline void insert(short int l, short int r, int val){
	hash_line *New = new hash_line;
	New->l = l, New->r = r, New->val = val, New->next = Hash[val % MOD];
	Hash[val % MOD] = New;
}

int main(){
	freopen("take5.in", "r", stdin);
	//freopen("data.out", "w", stdout);
	FILE *out = fopen("take5.out", "w");
	
	scanf("%d %d", &N, &S);
	for (int i = 1; i <= N; ++i){
		scanf("%d", &v[i]);

		for (int j = i - 1; j; --j)
			insert(j, i, hash(v[i] + v[j]) );
	}
	
	for (int i = 1; i <= N; ++i){
		for (int j = 0; j < MOD / 2; ++j)
			foreach(Hash[j]);
		//for (int j = i - 1; j; --j)
			//ans += find(S - v[i] - v[j], i, j);
	}

	fprintf(out, "%d", ans);
	printf("%f\n", (float)clock() / CLOCKS_PER_SEC);
	
	return 0;
}