Cod sursa(job #2130929)

Utilizator tanasaradutanasaradu tanasaradu Data 14 februarie 2018 08:33:53
Problema Numarare Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("numarare.in");
ofstream fout ("numarare.out");
const int Nmax = 100005;
queue < pair < int , int > > Q;
int a[Nmax] , n;
int main()
{
    int x , y;
    long long sol = 0;
    fin >> n;
    for(int i = 1 ; i <= n ; i++)
        fin >> a[i];
    for(int i = 1 ; i < n ; i++)
    {
        ++sol;
        Q . push({i , i + 1});
    }
    while(! Q . empty())
    {
        x = Q . front() . first;
        y = Q . front() . second;
        Q . pop();
        if((x - 1) >= 1 && (y + 1) <= n && a[x - 1] + a[y + 1] == a[x] + a[y])
        {
            sol++;
            Q . push({x - 1 , y + 1});
        }
    }
    fout << sol << "\n";
    fin.close();
    fout.close();
    return 0;
}