Cod sursa(job #1146360)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 18 martie 2014 21:46:46
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>

using namespace std;

int n,t,h,i;

int stack[50005];

int main() {
    ifstream f("nivele.in");
    ofstream g("nivele.out");
    f>>t;
    while(t--) {
        f>>n;
        h=0;
        for(i=1;i<=n;i++) {
            h++;
            f>>stack[h];
            while(h>1 && stack[h]==stack[h-1]) {
                h--;
                stack[h]--;
            }
        }
        if(h==1 && stack[1]==1)
            g<<"DA\n";
        else
            g<<"NU\n";
    }
    return 0;
}