Cod sursa(job #19091)

Utilizator pauldbPaul-Dan Baltescu pauldb Data 18 februarie 2007 19:05:47
Problema Amlei Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <stdio.h>
#include <algorithm>

using namespace std;

#define maxn 5010
#define mid 50
#define maxx 110

int a[maxn],b[maxn],c[maxx],d[maxx];
int n,m,N;

int egal(int x,int y)
{
    int i;
    
    memset(d,0,sizeof(d));
    memset(c,0,sizeof(c));
    
    for (i=1;i<=N;i++) 
    {
        d[a[x+i]+mid]++;
        c[b[y+i]+mid]++;
    }
    
    for (i=0;i<maxx;i++)
      if (c[i]!=d[i]) return 0;
      
    return 1;
}

int main()
{
    freopen("amlei.in","r",stdin);
    freopen("amlei.out","w",stdout);
    
    int i,j,found;
    
    while (!feof(stdin))
    {
          scanf("%d %d %d ",&N,&n,&m);
          for (i=1;i<=n*N;i++) scanf("%d ",&a[i]);
          for (i=1;i<=m*N;i++) scanf("%d ",&b[i]);
          
          for (i=1;i<=n;i++)
          {
            found=0;
            for (j=1;j<=m;j++)
              if (egal((i-1)*N,(j-1)*N)) 
              {
                   found=1;
                   break;
              }
              
            if (!found) 
            {
               printf("NU\n");
               break;
            }
          }
         if (found) printf("DA\n");
    }
    
    return 0;
}