Cod sursa(job #527999)

Utilizator AndreyPAndrei Poenaru AndreyP Data 1 februarie 2011 19:28:56
Problema Amlei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pii pair< int,int >
#define T 510
#define N 55

int n,t,u;
bitset< N > poz[2][T];
bitset< T > are;

inline void citire() {
	int x;

	for(int i=0; i<t; ++i) {
		for(int j=0; j<n; ++j) {
			scanf("%d",&x);
			if(x>0) 
				poz[0][i].set(x);
		}
	}

	for(int i=0; i<u; ++i) {
		for(int j=0; j<n; ++j) {
			scanf("%d",&x);
			if(x>0) 
				poz[1][i].set(x);
		}
	} 
}

inline bool rezolva() {
	bool gasit;
	for(int i=0; i<t; ++i) {
		gasit = false;
		for(int j=0; j<u; ++j) {
                	if(poz[0][i]==poz[1][j]) {
				gasit = true;
				are[j] = 1;
			}
		}

		if(gasit==false)
			return false;
	}

        for(int i=0; i<u; ++i) {
		if(!are[i])
			return false;
	}

	return true;
}

inline void refresh() {
	for(int i=0; i<t; ++i)
		poz[0][i].reset();

	for(int i=0; i<u; ++i)
		poz[1][i].reset();
}
		
int main() {
	freopen("amlei.in","r",stdin);
	freopen("amlei.out","w",stdout);

        while(scanf("%d%d%d",&n,&t,&u)!=EOF) {
		citire();
                if(rezolva())
			fputs("DA\n",stdout);
		else
			fputs("NU\n",stdout);
		refresh();
	}

	return 0;
}