Cod sursa(job #1469385)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 8 august 2015 08:15:06
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#include <algorithm>
#include <list>
using namespace std;

constexpr int sz = 666013;
list<pair<int, int> > el[sz];

void insert(const int x){
	auto it = find_if(begin(el[x%sz]), end(el[x%sz]), [x](const pair<int, int>& p){ return p.first == x; });
	if(it == end(el[x%sz])){
		el[x%sz].emplace_back(x, 1); }
	else{
		++(it->second); } }

int count(const int x){
	if(x < 0){
		return 0; }
	auto it = find_if(begin(el[x%sz]), end(el[x%sz]), [x](const pair<int, int>& p){ return p.first == x; });
	if(it == end(el[x%sz])){
		return 0; }
	else{
		return (it->second); } }

int main(){
	ifstream f("oite.in");
	ofstream g("oite.out");
	int n, l;
	f >> n >> l;
	vector<int> v(n);
	for(auto& x : v){
		f >> x; }
	int rez = 0;
	for(int third = 2; third+1 < n; ++third){
		for(int first = 0; first+1 < third; ++first){
			if(v[first] + v[third-1] <= l){
				insert(v[first] + v[third-1]); } }
		for(int fourth = third+1; fourth < n; ++fourth){
			rez += count(l - v[third] - v[fourth]); } }
	g << rez;
	return 0; }