Pagini recente » Cod sursa (job #1352941) | Cod sursa (job #3122037) | Cod sursa (job #1086790) | Cod sursa (job #93767) | Cod sursa (job #1913852)
#include <fstream>
#include <stack>
#include <string>
using namespace std;
ifstream in( "nivele.in" );
ofstream out( "nivele.out" );
const int NMAX = 50000;
int v[NMAX+2];
stack<int> st;
int N;
string ans[2] = {"NU\n", "DA\n"};
int main()
{
int T;
in >> T;
while( T--) {
in >> N;
for( int i = 1; i <= N; ++i ) {
int x;
in >> x;
while( !st.empty() && st.top() == x ) {
st.pop();
--x;
}
st.push( x );
}
bool ok = 1;
if( st.size() > 1 || st.top() != 1 ) ok = 0;
out << ans[ok];
}
return 0;
}