Cod sursa(job #712618)
Utilizator | Data | 13 martie 2012 17:37:42 | |
---|---|---|---|
Problema | Amlei | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.82 kb |
#include<cstdio>
#include<algorithm>
using namespace std;
int n,t,u,i,j,l,c[51],d[501][51],r,x,y,k,o,z[501],s,h,a;
int main()
{FILE *f=fopen("amlei.in","r"),*g=fopen("amlei.out","w");
while(!feof(f))
{fscanf(f,"%d%d%d",&n,&t,&u);
for(l=0,h=o=i=1;o<=t;i++)
{fscanf(f,"%d",&c[i]),s+=c[i];
if(i%n==0)
{sort(c+1,c+n+1);
for(k=1;k<=l;k<<=1);
for(j=0,r=k;r;r>>=1)
if(j+r<=l&&z[j+r]<=s)
j+=r;
for(y=1;z[j]==s&&y;j--)
{for(r=a=1;a<=n&&r;a++)
if(d[j][a]!=c[a])
r=0;
if(r)
y=0;}
if(y)
{j++,l++;
for(r=l;r>j;r--)
{z[r]=z[r-1];
for(a=1;a<=n;a++)
d[r][a]=d[r-1][a];}
for(z[j]=s,r=1;r<=n;r++)
d[j][r]=c[r];}
o++,s=i=0;}}
for(o=i=1;o<=u;i++)
{fscanf(f,"%d",&c[i]),s+=c[i];
if(i%n==0)
{sort(c+1,c+n+1);
for(j=0,r=k;r;r>>=1)
if(j+r<=l&&z[j+r]<=s)
j+=r;
for(y=1;z[j]==s;j--)
{for(r=a=1;a<=n&&r;a++)
if(d[j][a]!=c[a])
r=0;
if(r)
y=0;}
if(y)
h=0;
o++,s=i=0;}}
if(feof(f))
break;
fprintf(g,"%s\n",h?"DA":"NU");}
return 0;}