Submission #41542

#TimeUsernameProblemLanguageResultExecution timeMemory
41542farmersriceCarnival (CEOI14_carnival)C++14
100 / 100
10 ms2188 KiB
#include <bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") //#pragma GCC target ("avx,tune=native") //Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly /* TASK: hidden LANG: C++11 */ using namespace std; typedef long long ll; typedef pair<int, int> pair2; typedef pair<int, pair<int, int> > pair3; typedef pair<int, pair<int, pair<int, int> > > pair4; #define MAXN 200013 #define INF 1000000000000000000LL #define mp make_pair #define add push_back #define remove pop struct UnionFind { int * id; int * size; int count; UnionFind(int sz) { id = new int[sz]; size = new int[sz]; count = sz; for (int i = 0; i < sz; i++) { size[i] = 1; id[i] = i; } } UnionFind(){} bool sameset(int p, int q) { return find(p) == find(q); } int find(int p) { if (p != id[p]) { id[p] = find(id[p]); } return id[p]; } void merge(int p, int q) { int rootp = find(p); int rootq = find(q); if (rootp == rootq) return; if (size[rootp] < size[rootq]) { id[rootp] = rootq; size[rootq] += size[rootp]; } else { id[rootq] = rootp; size[rootp] += size[rootq]; } count--; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; UnionFind uf(n); for (int i = 0; i < n; i++) { vector<int> representatives; for (int j = 0; j < i; j++) { if (uf.find(j) == j) representatives.add(j); } cout << representatives.size() + 1 << ' '; for (int r : representatives) { cout << r + 1 << ' '; } cout << i + 1 << endl; int distinct; cin >> distinct; if (distinct == representatives.size() + 1) continue; //it's separate from all other groups //binary search on who it's with int start = 0; int end = representatives.size() - 1; while (start <= end) { int mid = (start + end) / 2; cout << mid - start + 1 + 1 << ' '; for (int j = start; j <= mid; j++) { cout << representatives[j] + 1 << ' '; } cout << i + 1 << endl; cin >> distinct; if (distinct == mid - start + 1 + 1) { //search to the right -- it doesn't match anything on the left start = mid + 1; } else { end = mid - 1; } } uf.merge(i, representatives[start]); } cout << 0 << ' '; map<int, int> clothes; int counter = 1; for (int i = 0; i < n; i++) { int group = uf.find(i); if (clothes.find(group) == clothes.end()) { clothes[group] = counter++; } cout << clothes[group] << ' '; } cout << endl; }

Compilation message (stderr)

carnival.cpp: In function 'int main()':
carnival.cpp:89:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (distinct == representatives.size() + 1) continue; //it's separate from all other groups
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...