Cod sursa(job #595876)

Utilizator mihaipopa12Popa Mihai mihaipopa12 Data 14 iunie 2011 19:06:39
Problema Oite Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<stdio.h>
#include<vector>

#define maxN 1050
#define MOD 500009

using namespace std;

FILE*f=fopen("oite.in","r");
FILE*g=fopen("oite.out","w");

int n,i,A[maxN],j,NrSol,list,found,S;
vector< pair<int,int> >G[MOD+5]; vector< pair<int,int> >::iterator itt;

inline void citire () {
	
	fscanf(f,"%d %d",&n,&S);
	for ( i = 1 ; i <= n ; ++i ){
		fscanf(f,"%d",&A[i]);
	}
}

inline void add( int x ){
	
	list = x % MOD; found = 0;
	for ( itt = G[list].begin() ; itt != G[list].end() ; ++itt ){
		if ( (*itt).first == x ){
			++(*itt).second; found = 1;
		}
	}
	if ( !found ){
		G[list].push_back( make_pair(x,1) );
	}
}

inline int appear ( int x ){
	list = x % MOD;
	for ( itt = G[list].begin() ; itt != G[list].end() ; ++itt ){
		if ( (*itt).first == x ){
			return ((*itt).second);
		}
	}
	return 0;
}

inline void solve () {
	
	for ( i = 2 ; i < n ; ++i ){
		for ( j = 1 ; j < i ; ++j ){
			add(A[i]+A[j]);
		}
		for ( j = i + 2 ; j <= n ; ++j ){
			NrSol += appear(S - A[i+1] - A[j]);
		}			
	}
	
	fprintf(g,"%d\n",NrSol);
}

int main () {
	
	citire();
	solve();
	
	fclose(f);
	fclose(g);
	
	return 0;
}