Cod sursa(job #1889697)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 22 februarie 2017 20:47:35
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 5e4 + 10;
short buf[maxn] = {}, *st = buf, *dr, depth = 1;

bool dfs(){
    return st == dr ? false :
        depth < *st ? (++depth && dfs() && st!=dr && dfs() && --depth) :
        depth == *st ? (bool)++st : false; }

ifstream f("nivele.in");
ofstream g("nivele.out");

int main(){
    int t;
    f >> t;
    while(t--){
        int n;
        f >> n;
        bool bad = false;
        for(int i = 0, x; i < n; ++i){
            f >> x;
            bad = (bad || (x > 1e5));
            buf[i] = x; }
        st = buf, dr = st+n, depth = 1;
        g << ((!bad && dfs()) ? "DA" : "NU") << '\n'; }
    return 0; }