Cod sursa(job #2434195)

Utilizator memecoinMeme Coin memecoin Data 30 iunie 2019 23:19:11
Problema Balanta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h> 
#include <string>

using namespace std;

ifstream fin("balanta.in");
ofstream fout("balanta.out");

int low[2024];
int high[2024];
int a[2024];
int b[2024];

int main() {

	int n, t;

	fin >> n >> t;

	for (int i = 1; i <= n; ++i) {
		low[i] = 1;
		high[i] = 1;
	}

	while (t > 0) {
		int m, r;
		int x;

		fin >> m;

		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));

		for (int i = 0; i < m; ++i) {
			fin >> x;
			a[x] = 1;
		}
		for (int i = 0; i < m; ++i) {
			fin >> x;
			b[x] = 1;
		}

		fin >> r;

		for (int i = 1; i <= n; ++i) {
			if (r == 0) {
				if (b[i] || a[i]) {
					high[i] = 0;
					low[i] = 0;
				}
			}
			if (r == 1) {
				if (!a[i]) {
					high[i] = 0;
				}
				if (!b[i]) {
					low[i] = 0;
				}
			}
			if (r == 2) {
				if (!a[i]) {
					low[i] = 0;
				}
				if (!b[i]) {
					high[i] = 0;
				}
			}
		}

		t--;
	}

	int nh = 0;
	int nl = 0;

	for (int i = 1; i <= n; ++i) {
		nl += low[i];
		nh += high[i];
	}

	if (nh == 1 && nl == 0) {
		for (int i = 1; i <= n; ++i) {
			if (high[i]) {
				fout << i;
				return 0;
			}
		}
	}

	if (nh == 0 && nl == 1) {
		for (int i = 1; i <= n; ++i) {
			if (low[i]) {
				fout << i;
				return 0;
			}
		}
	}

	fout << "0";

	return 0;
}