Pagini recente » Cod sursa (job #377488) | Cod sursa (job #791888) | Istoria paginii runda/fmi-no-stress-9/clasament | Cod sursa (job #110872) | Cod sursa (job #2024782)
#include <fstream>
#include <deque>
using namespace std;
ifstream f("nivele.in");
ofstream g("nivele.out");
int t, x, n;
deque <int> st;
int main()
{
f>>t;
for(int o = 1; o <= t; ++ o)
{
f>>n;
for(int i = 1; i <= n ; ++ i)
{
f>>x;
if(st.empty())
st.push_back(x);
else
{
if(x == st.back())
{
st.pop_back();
st.push_back(x - 1);
while(st.size() >= 2 && st[st.size() - 1] == st[st.size() - 2])
{
x = st.back();
st.pop_back();
st.pop_back();
st.push_back(x - 1);
}
}
else
st.push_back(x);
}
}
if(st.size() == 1 && st[0] == 1 )
g<<"DA"<<'\n';
else
g<<"NU"<<'\n';
st.clear();
}
return 0;
}