Cod sursa(job #144146)

Utilizator VmanDuta Vlad Vman Data 27 februarie 2008 11:46:18
Problema Nivele Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <stdio.h>
#include <string.h>

#define Nmax 50005

unsigned int N,NN;
int T;
long A;
int st[Nmax],dr[Nmax],stiva[Nmax],lvl,nod;

int main()
{
 freopen("nivele.in","r",stdin);
 freopen("nivele.out","w",stdout);
 scanf("%d",&T);
 while (T)
	{
	 --T;
	 scanf("%d",&NN);
	 N=NN;
	 nod=0;
	 lvl=1;
	 memset(st,0,sizeof(st));
	 memset(dr,0,sizeof(dr));
	 while (N)
		{
		 --N;
		 scanf("%ld",&A);
		 if (A>NN) { lvl=-1;break; }
		 //get there
		 while ((dr[stiva[lvl]]!=0)&&(lvl>=1)) --lvl;
		 if (lvl<1) break;
		 while (lvl<A)
			{
			 ++nod;
			 if (st[stiva[lvl]]==0) st[stiva[lvl]]=nod;
				else if (dr[stiva[lvl]]==0) dr[stiva[lvl]]=nod;
					else break;
			 stiva[++lvl]=nod;
			}
		 if (lvl!=A) { lvl=-1;break; }
		 --lvl;
		}
	 while (N) { --N;scanf("%d",&A); }
	 while (dr[stiva[lvl]]!=0 && lvl>1) --lvl;
	 if (lvl!=1) printf("NU\n");
		else printf("DA\n");
	}
 fclose(stdout);
 return 0;
}