Cod sursa(job #530774)

Utilizator dornescuvladVlad Eugen Dornescu dornescuvlad Data 8 februarie 2011 14:02:18
Problema Nivele Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <stack>

using namespace std;

const char iname[] = "nivele.in";
const char oname[] = "nivele.out";

ifstream fin(iname);
ofstream fout(oname);

int n, t, i, v[51000], j;
int st[1510], vf;

int main()
{
	fin >> t;
	for(j = 1; j <= t; j ++)
	{
		fin >> n;
		for(i = 1; i <= n; i ++)
			fin >> v[i];
		
		vf = 0;
		for(i = 1; i <= n; i ++)
		{	
			while(st[vf] == v[i])
				v[i]--, vf--;
			st[++vf] = v[i];
		}

		if(vf == 1 && st[1] == 1)
			fout << "DA\n";
		else
			fout << "NU\n";

	}
	return 0;
}