답안 #531051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531051 2022-02-27T14:04:16 Z mdubaisi Alkemija (COCI18_alkemija) C++14
8 / 80
40 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 ll N = 1e6 + 1;
const ll M = 30;
using namespace std;

bool have[N];
bool 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> x(l), y(r);
		reactions[i].need = vector<bool>(n + 1, false);
		for (int j = 0; j < l; j++) {
			cin >> x[j];
			if (!have[x[j]])
				reactions[i].need[x[j]] = !have[x[j]];
		}
		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:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int j = 0; j < reactions[i].need.size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 49256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -