Submission #495978

#TimeUsernameProblemLanguageResultExecution timeMemory
495978BlancaHMCarnival (CEOI14_carnival)C++14
100 / 100
10 ms296 KiB
#include <iostream> #include <vector> #include <map> #include <unordered_set> #include <set> #include <algorithm> using namespace std; vector<int> par; vector<int> roots; int root(int a) { if (a == par[a]) return a; return par[a] = root(par[a]); } void merge(int i, int j) { if (i == j) return; par[j] = i; auto it = find(roots.begin(), roots.end(), j); roots.erase(it, it+1); } void solve(int N, int C) { if (C == 1) { par.assign(N, 0); return; } par = vector<int>(N); for (int i = 0; i < N; i++) par[i] = i; roots = {}; int ans, costumesDiscovered = 0; for (int i = 0; i < N; i++) { if (N - i == C - costumesDiscovered) continue; // comprobaremos si hay un conjunto al que añadir a la persona if(roots.size()) { cout << (int)roots.size()+1 << " "; for (int r: roots) cout << r+1 << ' '; cout << i+1 << '\n'; cin >> ans; if (ans == (int) roots.size()) { // hay un conjunto -> hacemos búsqueda binaria para encontrar cuál int lo = 0, hi = (int) roots.size()-1, mid, k = 0; while(lo <= hi) { if (lo == hi) { k = lo; break; } mid = lo + (hi-lo)/2; cout << (mid-lo+2) << " "; for (int j = lo; j <= mid; j++) cout << roots[j]+1 << ' '; cout << i+1 << '\n'; cin >> ans; if (ans == (mid-lo+1)) { hi = mid; k = mid; } else lo = mid+1; } merge(i, roots[k]); } } // esta persona forma un conjunto nuevo if (par[i] == i) { costumesDiscovered++; roots.push_back(i); } } } int main() { int N, C; cin >> N; cout << N; for (int i = 1; i <= N; i++) cout << " " << i; cout << '\n'; cin >> C; solve(N, C); map<int, int> roots; int c = 1; for (int i = 0; i < N; i++) { if (roots.find(root(i)) == roots.end()) { roots[root(i)] = c++; } } int costumes[N]; for (int i = 0; i < N; i++) costumes[i] = roots[root(i)]; cout << "0"; for (int i = 0; i < N; i++) cout << " " << costumes[i]; cout << '\n'; return 0; }
#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...