Cod sursa(job #2911749)

Utilizator euyoTukanul euyo Data 1 iulie 2022 19:36:02
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin( "nivele.in" );
ofstream fout( "nivele.out" );

const int DIM = 50005; 

int readInt() {
  char ch;
  int n = 0;
  while ( isspace( ch = fin.get() ) );
  do { 
    n = n * 10 + ch - '0';
  } while ( isdigit( ch = fin.get() ) );
  return n;
}

int main() {
  int t, n, x;

  fin >> t;
  while ( t-- ) {
	fin >> n;
    vector<int> stk;
	for ( int i = 1; i <= n; ++i ) {
	  x = readInt();
	  while ( stk.size() && stk.back() == x ) {
		stk.pop_back();
		--x;
	  }
      stk.push_back(x);
	}
	fout << (stk.size() == 1 && stk.back() == 1 ? "DA\n" : "NU\n");
  }
  fin.close();
  fout.close();
  return 0;
}