Cod sursa(job #3356033)

Utilizator rares89_Dumitriu Rares rares89_ Data 29 mai 2026 02:34:49
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("nivele.in");
ofstream fout("nivele.out");

int main() {
    int t;
    fin >> t;
    
    for(; t; --t) {
        int n;
        fin >> n;
        
        vector<int> st;
        bool ok = true;
        
        for(int i = 0; i < n; ++i) {
            int x;
            fin >> x;
            
            if(!ok) continue;
            
            if(!st.empty() && x < st.back()) {
                ok = false;
            } else {
                st.push_back(x);
                while(st.size() >= 2 && st.back() == st[st.size() - 2]) {
                    int val = st.back();
                    st.pop_back();
                    st.pop_back();
                    st.push_back(val - 1);
                }
            }
        }
        
        if(ok && st.size() == 1 && st[0] == 1) {
            fout << "DA\n";
        } else {
            fout << "NU\n";
        }
    }
    
    fin.close();
    fout.close();
    return 0;
}