Cod sursa(job #1889683)

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

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

bool dfs(){
    if(st == dr || *st > 1e5) return false;
    else if(depth < *st){
        ++depth;
        if(!dfs() || st==dr || !dfs()) return false;
        --depth;
        return true; }
    else if(depth == *st){
        ++st;
        return true; }
    return false; }

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

int main(){
    int t;
    f >> t;
    while(t--){
        int n;
        f >> n;
        copy_n(istream_iterator<int>(f), n, buf);
        st = buf, dr = st+n, depth = 1;
        g << (dfs() ? "DA" : "NU") << '\n'; }
    return 0; }