Cod sursa(job #137614)

Utilizator AlxCojocaru Alexandru Alx Data 17 februarie 2008 12:47:58
Problema Nivele Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 4, Clasele 11-12 Marime 0.94 kb
#include <cstdio>
#include <cmath>
using namespace std;
long t,n,a[50000];
int main()
{
 freopen("nivele.in","r",stdin);
 freopen("nivele.out","w",stdout);
 scanf("%ld\n",&t);
 long i,j,ok;
 for (i=0;i<t;i++)
 {
  ok=1;
  scanf("%ld",&n);
  for (j=0;j<n;j++)
  {
   scanf("%ld",&a[j]);
   if (j>0&&(a[j]>a[j-1]+1||a[j]<a[j-1]))
    ok=0;
  }
  if (!ok)
  {
   printf("NU\n");
   continue;
  }
  j=1;
  while (j<n&&a[j]==a[0])
   j++;
  if (a[0]<16&&j>pow(double(2),double(a[0]-1)))
  {
   printf("NU\n");
   continue;
  }
  while (j<n)
  {
   long st=j;
   j++;
   while (j<n&&a[j]==a[st])
    j++;
   if (a[st]<16)
   {
    if ((j<n&&j-st!=pow(double(2),double(a[st]-1)))||(j==n&&j-st>pow(double(2),double(a[st]-1))))
    {
     printf("NU\n");
     ok=0;
     break;
    }
   }
   else
    if (j<n)
    {
     printf("NU\n");
     ok=0;
     break;
    }
  }
  if (ok)
   printf("DA\n");
 }
 return 0;
}