Cod sursa(job #1469381)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 8 august 2015 08:02:37
Problema Oite Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;

class my_multiset{
	unordered_map<long long, int> m;
public:
	void insert(const long long x){
		auto it = m.find(x);
		if(it == end(m)){
			m.emplace(x, 1); }
		else{
			++(it->second); } }
	int count(const long long x){
		auto it = m.find(x);
		return (it == end(m)) ? 0 : it->second; } };

constexpr long long sz = 10007;
my_multiset sets[sz];

void insert(const long long x){
	sets[x % sz].insert(x); }

int count(const long long x){
	return sets[x % sz].count(x); }

int main(){
	ifstream f("oite.in");
	ofstream g("oite.out");
	int n;
	long long l;
	f >> n >> l;
	vector<long long> v(n);
	for(auto& x : v){
		f >> x; }
	long long 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; }