Submission #1085386

#TimeUsernameProblemLanguageResultExecution timeMemory
1085386juicyCarnival (CEOI14_carnival)C++17
100 / 100
38 ms848 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  int n; cin >> n;
  vector<int> lab(n); iota(lab.begin(), lab.end(), 0);
  function<int(int)> find = [&](int u) {
    return lab[u] == u ? u : lab[u] = find(lab[u]);
  };
  auto ask = [&](vector<int> cnd) {
    cout << cnd.size() << " ";
    for (int x : cnd) {
      cout << x << " ";
    }
    cout << endl;
    int x; cin >> x;
    return x;
  };
  auto check = [&](vector<int> a, int i) {
    int x = ask(a);
    a.push_back(i + 1);
    int y = ask(a);
    return x + 1 != y; 
  };
  for (int i = 0; i < n; ++i) {
    vector<int> cnd;
    for (int j = 0; j < n; ++j) {
      if (find(j) == j && find(i) != j) {
        cnd.push_back(j + 1);
      }
    }
    int l = 1, r = cnd.size(), p = 0;
    while (l <= r) {
      int m = (l + r) / 2;
      auto a = vector(cnd.begin(), cnd.begin() + m);
      if (check(a, i)) {
        p = m;
        r = m - 1;
      } else {
        l = m + 1;
      }
    }
    if (p) {
      lab[cnd[p - 1] - 1] = i;
    }
  }
  vector<int> col(n);
  int c = 0;
  for (int i = 0; i < n; ++i) {
    if (lab[i] == i) { 
      col[i] = ++c;
    }
  }
  cout << 0 << " ";
  for (int i = 0; i < n; ++i) {
    cout << col[find(i)] << " ";
  }
  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...