Cod sursa(job #744513)

Utilizator padreatiAurelian Tutuianu padreati Data 8 mai 2012 21:24:53
Problema Numarare triunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string.h>
 
using namespace std;
 
void sol();
 
int main() {
    freopen("nrtri.in", "r", stdin);
    freopen("nrtri.out", "w", stdout);
    sol();
    return 0;
}
 
#define N 801
#define LEN 30001
 
int n;
int v[N];
 
void sol() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &v[i]);
    int cnt[LEN];
    for (int i = 0; i < n; i++) {
        if (cnt[v[i]]<i) {
            cnt[v[i]] = i; 
        }
    }
    for (int i=LEN-1; i>0; i--) {
        if(!cnt[i]) cnt[i]=cnt[i+1];
    }
    int t = 0;
    for (int i = 1; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (i > cnt[v[j] - v[i]])
                t += i - cnt[v[j] - v[i]];
    printf("%d\n", t);
}