Cod sursa(job #3181910)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 8 decembrie 2023 12:09:55
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <fstream>
#include <unordered_map>

using namespace std;

ifstream cin("nivele.in");
ofstream cout("nivele.out");

const int NMAX = 5e4;

bool numara(int x, unordered_map <int, int> fr){

    if(x == 1 && fr[x] != 1){

        return false;

    }

    if(x == 1 && fr[x] == 1){

        return true;

    }

    int val = fr[x];
    if(val % 2 == 1)
        return false;

    fr[x - 1] += val / 2;
    return numara(x - 1, fr);

}

int main(){

    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 0;
    cin >> t;

    while(t--){

        int n = 0;
        cin >> n;

        int maxi = 0, mini = 2e9;
        unordered_map <int, int> fr;

        for(int i = 0; i < n; i++){

            int x = 0;
            cin >> x;

            fr[x]++;
            maxi = max(maxi, x);
            mini = min(mini, x);
        }

        if(maxi - mini + 1 > n){

            cout << "NU\n";
            continue;

        }

        bool ok = numara(maxi, fr);

        if(ok == true){

            cout << "DA\n";

        }else{

            cout << "NU\n";

        }

    }

    return 0;
}