# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
565902 |
2022-05-21T14:08:23 Z |
Deepesson |
ICC (CEOI16_icc) |
C++17 |
|
114 ms |
524 KB |
#include <bits/stdc++.h>
#include "icc.h"
#define MAX 105
typedef std::pair<int,int> pii;
int query(int size_a, int size_b, int a[], int b[]);
int query(std::vector<int> a,std::vector<int> b){
for(auto&x:a)++x;
for(auto&x:b)++x;
return query(a.size(),b.size(),a.data(),b.data());
}
void setRoad(int a, int b);
void InformaRua(int a,int b){setRoad(a+1,b+1);}
int pai[MAX];
int find(int a){
if(pai[a]==a){
return a;
}
return pai[a]=find(pai[a]);
}
void Union(int a,int b){
a=find(a);
b=find(b);
pai[a]=b;
}
std::vector<std::vector<int>> gerar_grupos(int N){
std::map<int,std::vector<int>> mapa;
for(int i=0;i!=N;++i){
mapa[find(i)].push_back(i);
}
std::vector<std::vector<int>> res;
for(auto&x:mapa){
res.push_back(x.second);
}
return res;
}
int splits[20];
int andar[MAX];
void dnc(int l,int r,int nv){
if(l==r)return;
int m = (l+r)/2;
for(int i=l;i<=m;++i)andar[i]+=(1<<nv);
dnc(l,m,nv+1);
dnc(m+1,r,nv+1);
}
void add(std::vector<int>& ref,std::vector<int> cp){
for(auto&x:cp)ref.push_back(x);
}
void pruning(std::vector<int>& a,std::vector<int> b){
while(a.size()!=1){
int m = a.size()/2;
std::vector<int> c,d;
for(int i=0;i<m;++i){
c.push_back(a[i]);
}
for(int i=m;i!=a.size();++i){
d.push_back(a[i]);
}
if(query(c,b)){
a=c;
}else a=d;
}
}
void run(int N) {
for(int i=0;i!=MAX;++i)pai[i]=i;
for(int i=1;i!=N;++i){
auto grups = gerar_grupos(N);
memset(andar,0,sizeof(andar));
dnc(0,grups.size()-1,0);
// printf("Gerun %d\n",grups.size());
std::vector<int> l,r;
for(int j=0;j!=20;++j){
std::vector<int> a,b;
for(int k=0;k!=grups.size();++k){
if(!(andar[k]&(1<<j))){
add(a,grups[k]);
}else add(b,grups[k]);
}
// std::cout<<"check "<<a.size()<<" "<<b.size()<<"\n";
// std::cout<<"\n";
// for(auto&x:a)std::cout<<x<<" ";std::cout<<"\n";
// for(auto&x:b)std::cout<<x<<" ";std::cout<<"\n";
if(query(a,b)){
// std::cout<<"yey:)\n";
l=a;
r=b;
goto prox;
}
}
prox:
// printf("koi\n");
// for(auto&x:l)std::cout<<x<<" ";std::cout<<"\n";
//for(auto&x:r)std::cout<<x<<" ";std::cout<<"\n";
pruning(l,r);
pruning(r,l);
assert(r.size()==1);
assert(l.size()==1);
//printf("per\n");
InformaRua(l[0],r[0]);
Union(l[0],r[0]);
}
}
Compilation message
icc.cpp: In function 'void pruning(std::vector<int>&, std::vector<int>)':
icc.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=m;i!=a.size();++i){
| ~^~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int k=0;k!=grups.size();++k){
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Ok! 99 queries used. |
2 |
Correct |
5 ms |
468 KB |
Ok! 106 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
428 KB |
Ok! 547 queries used. |
2 |
Correct |
39 ms |
468 KB |
Ok! 667 queries used. |
3 |
Correct |
32 ms |
508 KB |
Ok! 663 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
468 KB |
Ok! 1531 queries used. |
2 |
Correct |
110 ms |
504 KB |
Ok! 1627 queries used. |
3 |
Correct |
101 ms |
504 KB |
Ok! 1612 queries used. |
4 |
Correct |
99 ms |
504 KB |
Ok! 1561 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
504 KB |
Ok! 1594 queries used. |
2 |
Correct |
99 ms |
508 KB |
Ok! 1596 queries used. |
3 |
Correct |
106 ms |
504 KB |
Ok! 1622 queries used. |
4 |
Correct |
97 ms |
468 KB |
Ok! 1540 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
524 KB |
Ok! 1626 queries used. |
2 |
Correct |
105 ms |
516 KB |
Ok! 1622 queries used. |
3 |
Correct |
107 ms |
504 KB |
Ok! 1634 queries used. |
4 |
Correct |
101 ms |
520 KB |
Ok! 1608 queries used. |
5 |
Correct |
99 ms |
504 KB |
Ok! 1545 queries used. |
6 |
Correct |
103 ms |
512 KB |
Ok! 1558 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
516 KB |
Ok! 1622 queries used. |
2 |
Correct |
104 ms |
468 KB |
Ok! 1622 queries used. |