Submission #676454

# Submission time Handle Problem Language Result Execution time Memory
676454 2022-12-31T01:56:24 Z badont Alkemija (COCI18_alkemija) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }

#ifdef LOCAL
#define debug(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define debug(...) "zzz"
#endif

using LL = long long;
using LD = long double;
using pii = pair<LL,LL>;

#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

template<typename T, typename = void> struct is_iterable : false_type {};
template<typename T> struct is_iterable<T, void_t<decltype(begin(declval<T>())),decltype(end(declval<T>()))>> : true_type {};
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v) {
	cout << "["; 
	for (auto it = v.begin(); it != v.end();) {
		cout << *it;
		if (++it != v.end()) cout << ", ";
	}
	return cout << "]";
}

//var 
LL T;

void solve() {
	LL n, m;
	cin >> n >> m;

	set<LL> v;
	while (m--) {
		LL x; cin >> x;
		x--;
		v.insert(x);
	}

	LL k; cin >> k;
	vector<pair<set<LL>, set<LL>>> a(k);
	vector<vector<LL>> hit(n);
	F0R (i, k) {
		auto& [s1, s2] = a[i];
		LL l, r;
		cin >> l >> r;
		while (l--) {
			LL x; cin >> x; x--;
			if (!v.count(x)) {
				s1.insert(x);
				hit[x].pb(i);
			}
		}

		while (r--) {
			LL x; cin >> x; x--;
			s2.insert(x);
		}
	}

	queue<LL> rmv;
	F0R (i, k) {
		if (a[i].f.empty()) {
			rmv.push(i);
		} 
	}

	vector<LL> visitedSet(k);
	while (!rmv.empty()) {
		LL g = rmv.front();
		rmv.pop();
		if (visitedSet[g])
			continue;
		visitedSet[g] = true;

		auto& [s1, s2] = a[g];
		assert(s1.empty());

		for (auto u : s2) if (!v.count(u)) {
			v.insert(u);
			for (auto z : hit[u]) {
				if (a[z].f.count(u)) {
					a[z].f.erase(u);
					if (a[z].f.empty()) {
						rmv.push(z);
					}
				}
			}
		}
		s2.clear();
	}

	vector<LL> ans;
	for (auto u : v)ans.pb(u);

	cout << ans.size() << '\n';
	F0R (i, (int)ans.size()) 
		cout << ans[i] + 1 << " \n"[i == (int)ans.size() - 1];

}

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);

	T = 1;
	//cin >> T;
	FOR(t, T)
		solve();

	cout.flush();
	return 0;
}

Compilation message

alkemija.cpp:26:44: error: 'void_t' was not declared in this scope
   26 | template<typename T> struct is_iterable<T, void_t<decltype(begin(declval<T>())),decltype(end(declval<T>()))>> : true_type {};
      |                                            ^~~~~~
alkemija.cpp:26:44: note: 'std::void_t' is only available from C++17 onwards
alkemija.cpp:26:108: error: template argument 2 is invalid
   26 | template<typename T> struct is_iterable<T, void_t<decltype(begin(declval<T>())),decltype(end(declval<T>()))>> : true_type {};
      |                                                                                                            ^~
alkemija.cpp: In function 'void solve()':
alkemija.cpp:56:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |   auto& [s1, s2] = a[i];
      |         ^
alkemija.cpp:88:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |   auto& [s1, s2] = a[g];
      |         ^