Submission #531060

# Submission time Handle Problem Language Result Execution time Memory
531060 2022-02-27T14:34:17 Z mdubaisi Alkemija (COCI18_alkemija) C++14
8 / 80
52 ms 65540 KB
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#define endl "\n"
#define debug(x) cout << "DEBUG" << x << ": "
#define fastimize() ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(v) (v.begin()), (v.end())
#define endof(v) v[v.size() - 1]
#define setall(a, val) memset(a, val, sizeof a)
#define range(v, s, e) (v.begin() + s), (v.begin() + e)
#define ll long long
const ll MOD = 1e9 + 7;
const int N = 1e6 + 1;
const ll M = 30;
using namespace std;

bool have[N], used[N];

struct Reaction {
	vector<int> to;
	vector<bool> need;
	Reaction() : to(vector<int>(0)), need(vector<bool>(0)) {}
};
int main() {
	fastimize();

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		have[x] = true;
	}

	int k;
	cin >> k;
	vector<Reaction> reactions(k);
	for (int i = 0; i < k; i++) {
		int l, r;
		cin >> l >> r;

		vector<int> y(r);
		reactions[i].need = vector<bool>(n + 1, false);
		for (int j = 0; j < l; j++) {
			int x;
			cin >> x;
			if (!have[x])
				reactions[i].need[x] = !have[x];
		}
		for (int j = 0; j < r; j++)
			cin >> y[j];

		reactions[i].to = y;
	}

	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = 0; i < k; i++) {
			if (!used[i]) {
				for (int j = 0; j < reactions[i].need.size(); j++) {
					if (have[reactions[i].need[j]])
						reactions[i].need[j] = false;
				}
				if (reactions[i].need != vector<bool>(n + 1, false))
					break;

				flag = true;
				used[i] = true;
				for (int x : reactions[i].to)
					have[x] = true;
				break;
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += have[i];
	cout << ans << endl;
	for (int i = 1; i <= n; i++)
		if (have[i])
			cout << i << ' ';
	cout << endl;
}

Compilation message

alkemija.cpp: In function 'int main()':
alkemija.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int j = 0; j < reactions[i].need.size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 49268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 40 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 46 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -