# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
565904 |
2022-05-21T14:09:21 Z |
Deepesson |
ICC (CEOI16_icc) |
C++17 |
|
128 ms |
596 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);
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]);
}
if(query(a,b)){
l=a;
r=b;
goto prox;
}
}
prox:
pruning(l,r);
pruning(r,l);
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:86:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int k=0;k!=grups.size();++k){
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
596 KB |
Ok! 99 queries used. |
2 |
Correct |
7 ms |
596 KB |
Ok! 106 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
468 KB |
Ok! 547 queries used. |
2 |
Correct |
52 ms |
484 KB |
Ok! 667 queries used. |
3 |
Correct |
36 ms |
468 KB |
Ok! 663 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
468 KB |
Ok! 1531 queries used. |
2 |
Correct |
123 ms |
500 KB |
Ok! 1627 queries used. |
3 |
Correct |
128 ms |
504 KB |
Ok! 1612 queries used. |
4 |
Correct |
113 ms |
520 KB |
Ok! 1561 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
520 KB |
Ok! 1594 queries used. |
2 |
Correct |
119 ms |
504 KB |
Ok! 1596 queries used. |
3 |
Correct |
122 ms |
512 KB |
Ok! 1622 queries used. |
4 |
Correct |
112 ms |
496 KB |
Ok! 1540 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
468 KB |
Ok! 1626 queries used. |
2 |
Correct |
114 ms |
468 KB |
Ok! 1622 queries used. |
3 |
Correct |
122 ms |
504 KB |
Ok! 1634 queries used. |
4 |
Correct |
119 ms |
512 KB |
Ok! 1608 queries used. |
5 |
Correct |
114 ms |
500 KB |
Ok! 1545 queries used. |
6 |
Correct |
115 ms |
492 KB |
Ok! 1558 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
512 KB |
Ok! 1622 queries used. |
2 |
Correct |
119 ms |
516 KB |
Ok! 1622 queries used. |