Cod sursa(job #1744647)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 20 august 2016 02:23:46
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
#include <algorithm>
#include <cstring>

using namespace std;

ifstream cin("nivele.in");
ofstream cout("nivele.out");

const int MAXN = 50000;

int Stack[1 + MAXN];

int main() {
    int tests;
    cin >> tests;
    for (int test = 1; test <= tests; test++) {
        int n;
        cin >> n;
        int top = 0;
        for (int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            while (top > 0 && x == Stack[top] && x > 1) {
                top--;
                x--;
            }
            top++;
            Stack[top] = x;
        }
        if (top == 1 && Stack[top] == 1)
            cout << "DA\n";
        else
            cout << "NU\n";
    }
    return 0;
}