Submission #476239

# Submission time Handle Problem Language Result Execution time Memory
476239 2021-09-25T14:22:53 Z Hamed5001 Carnival (CEOI14_carnival) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int mxN = 150;
DSU d(mxN);

struct DSU {
	int N;
	vector<int> P;

	DSU(int N) : N(N) {
		P.resize(N);
		for (int i = 0; i < N; i++)
			P[i] = i;
	}

	int get_parent(int a) {
		return P[a] = (P[a] == a ? a : get_parent(P[a]));
	}

	void unite(int a, int b) {
		a = get_parent(a);
		b = get_parent(b);
		P[a] = b;
	}
};

bool query(int l, int r, int x) {
	set<int> st;
	cout << r - l + 2;
	for (int i = l; i <= r; i++) {
		st.insert(d.get_parent(i));
		cout << d.get_parent(i)+1 << ' ';
	}
	cout << x+1 << endl;
	int res;
	cin >> res;
	return res == st.size();
}

void solve() {
	int N;
	cin >> N;
	int id = 1;
	vector<int> ans(N);
	ans[1] = id++;
	for (int i = 1; i < N; i++) {
		if (query(0, i-1, i)) {
			ans[i] = id++;
			continue;
		}
		int l = 0, r = i-1, mid;
		while(l < r) {
			mid = (l+r)>>1;
			if (query(0, mid, i))
				l = mid+1;
			else
				r = mid;
		}
		ans[i] = ans[l];
		d.unite(i, l);
	}

	cout << 0 << endl;
	for (auto &it : ans) cout << it << ' ';
	cout << endl;
}

int main() {

	
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	solve();
	return 0;
}

Compilation message

carnival.cpp:7:1: error: 'DSU' does not name a type
    7 | DSU d(mxN);
      | ^~~
carnival.cpp: In function 'bool query(int, int, int)':
carnival.cpp:34:13: error: 'd' was not declared in this scope
   34 |   st.insert(d.get_parent(i));
      |             ^
carnival.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  return res == st.size();
      |         ~~~~^~~~~~~~~~~~
carnival.cpp: In function 'void solve()':
carnival.cpp:63:3: error: 'd' was not declared in this scope
   63 |   d.unite(i, l);
      |   ^