Cod sursa(job #1990590)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 12 iunie 2017 17:17:54
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("progr2.in");
ofstream g("progr2.out");

const int NMax = 2002;

int t,n,x;
int a[NMax];

int main()
{
    f >> t;
    while(t--){
        f >> n;
        map<int,int> dp[NMax];
        for(int i = 1; i <= n; ++i){
            f >> a[i];
            for(int j = 1; j < i; ++j){
                if(dp[j].find(a[i] - a[j]) != dp[j].end())
                    dp[i][a[i] - a[j]] = dp[j][a[i] - a[j]] + 1;
                else
                    dp[i][a[i] - a[j]] = 1;
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; ++i){
            for(auto j : dp[i]){
                ans += j.second;
            }
        }
        g << ans << '\n';
    }

    return 0;
}