Cod sursa(job #1469376)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 8 august 2015 07:52:24
Problema Oite Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 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; } };

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;
	my_multiset s;
	for(int third = 2; third+1 < n; ++third){
		for(int first = 0; first+1 < third; ++first){
			s.insert(v[first] + v[third-1]); }
		for(int fourth = third+1; fourth < n; ++fourth){
			rez += s.count(l - v[third] - v[fourth]); } }
	g << rez;
	return 0; }