Cod sursa(job #2378295)

Utilizator Andrei-27Arhire Andrei Andrei-27 Data 11 martie 2019 22:31:42
Problema Nivele Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
using namespace std ;
ifstream in ("nivele.in") ;
ofstream out ("nivele.out") ;
int n , lvlmax , x , i , sw , t ;
int main ()
{
    in >> t ;
    while ( t -- )
    {
    lvlmax = 0 ;
    in >> n ;
    int64_t lvl [ n + 5 ] = {0} ;
    for ( i = 1 ; i <= n ; ++ i )
    {
        in >> x ;
        lvl [ x ] ++ ;
        lvlmax = max ( lvlmax , x ) ;
    }
    sw = 1 ;
    if ( lvlmax > 1 )
    for ( i = lvlmax ; i > 1 ; i -- )
    {
        if ( lvl [ i ] & 1 )    { sw = 0 ; break ; }
        lvl [ i - 1 ] += lvl [ i ] >> 1 ;
        if ( !lvl [ i ] && i != 1 ) { sw = 0 ; break ; }
    }
    if ( lvl [ 1 ] != 1 )    sw = 0 ;
    if ( sw )   out << "DA\n" ;
    else        out << "NU\n" ;
    }
}