Cod sursa(job #2400282)

Utilizator petru.ciocirlanPetru Ciocirlan petru.ciocirlan Data 8 aprilie 2019 16:28:27
Problema Medie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
using namespace std;

#define FILE_NAME "medie"
ifstream in (FILE_NAME".in");
ofstream out(FILE_NAME".out");

constexpr int MAX_VAL = 7000 + 4;
constexpr int MAX_DIM = 9000 + 4;
int Vect[MAX_DIM], Freq[MAX_VAL], Count[MAX_VAL];

int main()
{
    int N;
    in >> N;

    for(int i = 1; i <= N; ++i)
    {
        in >> Vect[i];
        ++Count[Vect[i]];
        for(int j = 1; j < i; ++j)
            if((Vect[i] + Vect[j]) % 2 == 0)
                ++Freq[(Vect[i] + Vect[j])>>1];
    }

    int Result = 0;
    for(int i = 1; i <= N; ++i)
        if(Count[Vect[i]])
            Result += Freq[Vect[i]] - Count[Vect[i]] + 1;

    out << Result;

    return 0;
}