#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
344 KB |
Output is correct |
3 |
Correct |
17 ms |
600 KB |
Output is correct |
4 |
Correct |
23 ms |
468 KB |
Output is correct |
5 |
Correct |
9 ms |
344 KB |
Output is correct |
6 |
Correct |
10 ms |
600 KB |
Output is correct |
7 |
Correct |
16 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
600 KB |
Output is correct |
2 |
Correct |
11 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
344 KB |
Output is correct |
4 |
Correct |
20 ms |
600 KB |
Output is correct |
5 |
Correct |
10 ms |
340 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
12 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
600 KB |
Output is correct |
3 |
Correct |
14 ms |
344 KB |
Output is correct |
4 |
Correct |
28 ms |
600 KB |
Output is correct |
5 |
Correct |
10 ms |
344 KB |
Output is correct |
6 |
Correct |
14 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
468 KB |
Output is correct |
2 |
Correct |
13 ms |
344 KB |
Output is correct |
3 |
Correct |
28 ms |
848 KB |
Output is correct |
4 |
Correct |
24 ms |
476 KB |
Output is correct |
5 |
Correct |
16 ms |
344 KB |
Output is correct |
6 |
Correct |
19 ms |
600 KB |
Output is correct |
7 |
Correct |
14 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
712 KB |
Output is correct |
2 |
Correct |
16 ms |
600 KB |
Output is correct |
3 |
Correct |
18 ms |
344 KB |
Output is correct |
4 |
Correct |
19 ms |
504 KB |
Output is correct |
5 |
Correct |
17 ms |
600 KB |
Output is correct |
6 |
Correct |
18 ms |
468 KB |
Output is correct |
7 |
Correct |
38 ms |
708 KB |
Output is correct |