Cod sursa(job #2036265)

Utilizator victoreVictor Popa victore Data 10 octombrie 2017 16:02:23
Problema Nivele Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<cstdio>
#include<algorithm>
#include<stack>

using namespace std;


stack<int> st;
int n;

int main()
{
    freopen("nivele.in","r",stdin);
    freopen("nivele.out","w",stdout);

    int i,j,q;

    scanf("%d",&q);

    while(q--)
    {
        scanf("%d",&n);

        while(!st.empty())
            st.pop();
        int x;
        scanf("%d",&x);
        st.push(x);

        for(i=2;i<=n;++i)
        {
            scanf("%d",&x);
            while(x>1 && st.top() == x)
            {
                st.pop();
                x--;
            }

            st.push(x);
        }

        if(st.top() == 1)
            printf("DA\n");
        else
            printf("NU\n");
    }
}