Cod sursa(job #476657)

Utilizator andra23Laura Draghici andra23 Data 11 august 2010 23:17:44
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include<iostream>
#include<fstream>
#include<algorithm>

using namespace std;

int a[50010], s[50010];

int main(){
    ifstream f("nivele.in");
    ofstream g("nivele.out");
    int n, t, i, j, k, x, cod, vf;
    
    f>>t;
    
    for (k = 1; k <= t; k++){
        f>>n;
        for (i = 1; i <= n; i++)
            f>>a[i]; 
        cod = 1;
        if (a[1] == 1)
            if (n == 1)
                g<<"DA"<<'\n';
            else {
                g<<"NU"<<'\n';
                continue;
            }
        else {
            vf = 1;
            s[vf] = a[1];
            for (i = 2; i <= n; i++){
                if (a[i] == 1)
                    cod = 0;
                else {
                    if (a[i] == s[vf]){
                        s[vf] = s[vf] - 1;
                        while (vf >= 2 && s[vf] == s[vf-1]){
                            vf--;
                            s[vf] = s[vf]-1;
                        }
                    }
                    else {
                        vf++;
                        s[vf] = a[i];
                    }
                }
            }
        }
        if (cod == 1 && vf == 1 && s[vf] == 1)
            g<<"DA"<<'\n';
        else 
            g<<"NU"<<'\n'; 
    }
    
    return 0;
}