Cod sursa(job #2538781)

Utilizator Mircea_DonciuDonciu Mircea Mircea_Donciu Data 5 februarie 2020 08:54:04
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda simulare_miri Marime 0.61 kb
#include <fstream>

using namespace std;
int t,n,x,k,w[50005];
int main()
{
    ifstream f("nivele.in");
    ofstream g("nivele.out");
    f>>t;
    while(t)
    {
        t--;
        f>>n;
        while(n)
        {
            n--;
            f>>x;
            k++;
            w[k]=x;
            while(k>1&&w[k]==w[k-1])
            {
                w[k]=0;
                k--;
                w[k]--;
            }
        }
        if(k==1&&w[k]==1) g<<"DA\n";
        else g<<"NU\n";
        while(k)
        {
            w[k]=0;
            k--;
        }
    }
    return 0;
}