Cod sursa(job #2532027)

Utilizator rapunzelMihnea Andreescu rapunzel Data 27 ianuarie 2020 10:08:57
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>

using namespace std;

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

const int N = 50000 + 7;
int n;
int stk[N];
int top;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        top = 0;
        for (int i = 1; i <= n; i++)
        {
            int x;
            cin >> x;
            stk[++top] = x;
            while (top >= 2 && stk[top] == stk[top - 1])
            {
                top--;
                stk[top]--;
            }
        }
        if (top == 1 && stk[1] == 1)
        {
            cout << "DA\n";
        }
        else
        {
            cout << "NU\n";
        }
    }
}