# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057382 |
2024-08-13T18:33:15 Z |
1ne |
Carnival (CEOI14_carnival) |
C++14 |
|
5 ms |
600 KB |
/*
* author : Apiram
* created: 13.08.2024 23:27:53
*/
#include<bits/stdc++.h>
using namespace std;
struct DSU{
vector<int>parent,sz;
DSU(int n){
parent.resize(n);
sz.resize(n,1);
iota(parent.begin(),parent.end(),0);
}
int findsets(int v){
if (v == parent[v]){
return v;
}
parent[v] = findsets(parent[v]);
return parent[v];
}
bool unionset(int u,int v){
u = findsets(u);
v = findsets(v);
if (u == v){
return false;
}
if (sz[v] > sz[u]){
swap(u,v);
}
parent[v] = u;
sz[u]+=sz[v];
return true;
};
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
DSU st(n);
vector<bool>visited(n,false);
auto query = [&](int l,int r){
int cnt = 0;
for (int i = l;i<=r;++i){
if (!visited[i]){
cnt++;
}
}
if (cnt <= 1){
return 0;
}
cout<<cnt;
for (int i = l;i<=r;++i){
if (!visited[i]){
cout<<" "<<i + 1;
}
}
cout<<endl;
int a;cin>>a;
if (cnt == a)return 0;
return 1;
};
for (int i = 0;i<n;++i){
int left = i + 1,right = n - 1,pos = -1;
while(left<=right){
int mid = (left + right)>>1;
if (query(i,mid)){
right = mid - 1;
pos = mid;
}
else{
left = mid + 1;
}
}
if (pos == -1)break;
left = i,right = pos - 1;
int pos2 = -1;
while(left<=right){
int mid = (left + right)>>1;
if (query(mid,pos)){
left = mid + 1;
pos2 = mid;
}
else{
right = mid - 1;
}
}
st.unionset(pos,pos2);
visited[pos] = true;
}
cout<<0<<" ";
vector<int>ans;
for (int i = 0;i<n;++i){
ans.push_back(st.findsets(i));
}
sort(ans.begin(),ans.end());
ans.erase(unique(ans.begin(),ans.end()),ans.end());
for (int i = 0;i<n;++i){
cout<<(lower_bound(ans.begin(),ans.end(),st.findsets(i)) - ans.begin()) + 1<<" ";
}
cout<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Integer 15 violates the range [1, 11] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
344 KB |
Integer 6 violates the range [1, 5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Integer 2 violates the range [1, 1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
344 KB |
Integer 7 violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
600 KB |
Integer 3 violates the range [1, 2] |
2 |
Halted |
0 ms |
0 KB |
- |