Cod sursa(job #18480)

Utilizator tvladTataranu Vlad tvlad Data 18 februarie 2007 12:23:04
Problema Amlei Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 2, Clasa a 10-a Marime 1.04 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int TU = 500;
const int N = 50;
int n,t,u;
long long a[TU];
long long b[TU];

void set1 ( long long &x, int k ) {
    long long aux = 1<<(k-1);
	x = x | aux;
}

bool eq ( long long a[], long long b[] ) {
	for (int i = 0; i<n; ++i) {
		if (a[i] != b[i]) return false;
	}
	return true;
}

int main() {
	freopen("amlei.in","r",stdin);
	freopen("amlei.out","w",stdout);
	while (not(feof(stdin))) {
		scanf("%d %d %d",&n,&t,&u);
		for (int i = 0; i<n; ++i) {
		    a[i] = 0;
		    b[i] = 0;
		}
		for (int i = 0; i<n; ++i) {
			for (int j = 0; j<t; ++j) {
				int aux;
				scanf("%d",&aux);
				int faux = fabs(aux);
				if (aux > 0) {
				    set1(a[i],faux);
				}
			}
		}
		for (int i = 0; i<n; ++i) {
			for (int j = 0; j<u; ++j) {
				int aux;
				scanf("%d",&aux);
				int faux = fabs(aux);
				if (aux > 0) {
				    set1(b[i],faux);
				}
			}
		}
		scanf("\n");
		sort(a,a+n);
		sort(b,b+n);
		if (eq(a,b)) {
			printf("DA\n");
		} else {
			printf("NU\n");
		}
	}
	return 0;
}