Cod sursa(job #2741606)

Utilizator PatruMihaiPatru Mihai PatruMihai Data 16 aprilie 2021 18:31:10
Problema Oite Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

ofstream fout("oite.out");
//ifstream fin("oite.in");

int v[1030];
unordered_map <int, int> h;


class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;
 
	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}
 
public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}
	
	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
	
	InParser& operator >> (long long &n) {
		char c;
		n = 0;
		while (!isdigit(c = read_ch()) && c != '-');
		long long sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};

InParser fin("oite.in");

int main()
{
    int n, l;
    int total = 0;


    fin >> n >> l;

    for(int i = 1; i <= n; i++)
    {
        fin >> v[i];
    }

    h[v[1] + v[2]]++;

    for(int i = 3; i <= n - 1; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            total += h[l - v[i] - v[j]];
        }

        for(int j = 1; j <= i - 1; j++)
        {
            h[v[i] + v[j]]++;
        }
    }  

    fout << total;

    return 0;
}