Cod sursa(job #1600274)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 14 februarie 2016 20:29:21
Problema Oite Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
// Template v2
#define pb push_back
#define mp make_pair
#define first x
#define second y
#define l(x) x<<1
#define r(x) x<<1 | 1
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PKK;
// primes less than 100
const int PRIM[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const int CMAX = 350;
const int MOD = 10007;
const int NMAX = 1234;
const short INF16 = 32000;
const int INF = int(1e9);
const LL INF64 = LL(1e18);
const LD EPS = 1e-9, PI = acos(-1.0);

list<int> M[MOD];
int l,n,rs;
int A[NMAX];

void read()
{
	cin>>n>>l;
	for(int i=1; i<=n; ++i)
		cin>>A[i];
}


void solve()
{
	sort(A+1, A+n+1);

	for(int i=3; i<=n; ++i)
		for(int j=i+1; j<=n; ++j)
			M[(A[i]+A[j])%MOD].pb(A[i]+A[j]);
	for(int i=2; i<=n-2; ++i)
	{
		for(int j=1; j<i; ++j)
			rs+=count(M[(l-(A[i]+A[j]))%MOD].begin(),M[(l-(A[i]+A[j]))%MOD].end(), l-(A[i]+A[j]));

		for(int j=i+2; j<=n; ++j)
			M[(A[i+1]+A[j])%MOD].erase(find(M[(A[i+1]+A[j])%MOD].begin(),M[(A[i+1]+A[j])%MOD].end(), A[i+1]+A[j]));
	}
	cout<<rs<<"\n";
}


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cout << setprecision(16) << fixed;

    assert(freopen("oite.in", "rt", stdin));
    assert(freopen("oite.out", "wt", stdout));

    read();
    solve();

    return 0;
}