Cod sursa(job #3148263)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 30 august 2023 14:03:01
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
#include <stack>
#include <vector>

using namespace std;

ifstream cin("nivele.in");
ofstream cout("nivele.out");

void test_case()
{
	int n;
	cin >> n;
	
	vector<int> stack(n + 1, 0);
	int st_ind = 0;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;

		stack[++st_ind] = x;
		while(st_ind > 1 && stack[st_ind] == stack[st_ind - 1])
		{
			stack[st_ind - 1]--;
			st_ind--;
		}
	}

	if(st_ind == 1 && stack[1] == 1)
		cout << "DA" << '\n';
	else
		cout << "NU" << '\n';
}

int main()
{
	int T;
	cin >> T;
	while(T--)
		test_case();

	return 0;
}