Cod sursa(job #3253581)

Utilizator stefR2020StefanRadulescu stefR2020 Data 3 noiembrie 2024 15:49:27
Problema Nivele Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
#include <stack>

using namespace std;

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

int t,n,x;

void solve()
{
    cin>>n;
    bool ok=0;
    stack<int> s;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        ok=0;
        while(!s.empty() && s.top()==x)
        {
            ok=1;
            s.pop();
            x--;
        }
        if(x)
            s.push(x);
    }
    if(s.size()!=1)
        cout<<"NU";
    else
        cout<<"DA";
    cout<<'\n';
}

int main()
{
    cin>>t;
    while(t--)
        solve();
    return 0;
}