Cod sursa(job #284261)

Utilizator AstronothingIulia Comsa Astronothing Data 21 martie 2009 14:19:14
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <fstream>
#include <stack>

using namespace std;

long long power2[] = {1LL,2LL,4LL,8LL,16LL,32LL,64LL,128LL,256LL,512LL,
1024LL,2048LL,4096LL,8192LL,16384LL,32768LL,65536LL,131072LL,262144LL,524288LL,
1048576LL,2097152LL,4194304LL,8388608LL,16777216LL,33554432LL,67108864LL,134217728LL,268435456LL,536870912LL,
1073741824LL};

int main()
{
    ifstream f("nivele.in");
    ofstream f2("nivele.out");

    int t;
    f>>t;



    for(int h=0;h<t;h++)
    {
        stack<int> s;

        int n;
        f>>n;

        int x;
        f>>x;
        s.push(x);

        for(int g=1;g<n;g++)
        {
            int y;
            f>>y;
            while(!s.empty() && y==s.top())
            {
                s.pop();
                y--;
            }
            s.push(y);
        }

        long long check = s.top();
        int l = s.size();
        if(s.size()==power2[check-1])
        {
            bool ok=1;
            while(!s.empty() && ok)
            {
                long long z = s.top();
                s.pop();
                if(z!=check) ok=0;
                else check = z;
            }
            if(ok) f2<<"DA\n";
            else f2<<"NU\n";
        }
        else f2<<"NU\n";


    }

    f.close();
    f2.close();
    return 0;
}