#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
const int N = 101;
int p[N], sz[N];
vector<int> comp[N];
int lg[N];
int find(int v){
if(p[v]==v)return v;
return p[v]=find(p[v]);
}
void merge(int v, int u){
v=find(v);
u=find(u);
if(u==v)return;
if(sz[u]<sz[v])swap(u, v);
p[v]=u;
sz[u]+=sz[v];
for(int e : comp[v])comp[u].push_back(e);
}
int genrand(){
int ret=0;
for(int i=0; i< 10; i++){
ret+=(1<<i) * (rand()%2);
}
return ret;
}
void run(int n){
for(int i=1; i<=n; i++){
p[i]=i;
sz[i]=1;
comp[i].push_back(i);
}
for(int i=2; i<N; i++)lg[i]=lg[i/2]+1;
for(int i=0; i< n-1; i++){
set<int> st;
for(int j=1; j<=n; j++)st.insert(find(j));
vector<int> a;
for(auto p : st)a.push_back(p);
vector<int> st1, st2;
vector<int> ord;
for(int i=0; i<=lg[a.size()-1]; i++){
ord.push_back(i);
}
for(int i=0; i<50; i++){
int r1 = rand()%ord.size();
int r2 = rand()%ord.size();
swap(ord[r1], ord[r2]);
}
for(int j : ord){
for(int k=0; k<a.size(); k++){
int x = k>>j;
if(x&1){
for(int e : comp[a[k]])st1.push_back(e);
}
else{
for(int e : comp[a[k]])st2.push_back(e);
}
}
int sz1=st1.size(), sz2=st2.size();
int fst[sz1], scd[sz2];
for(int i=0; i< sz1; i++)fst[i]=st1[i];
for(int i=0; i< sz2; i++)scd[i]=st2[i];
if(query(sz1, sz2, fst, scd))break;
st1.clear(); st2.clear();
}
vector<int> nscd = st2;
int sz1 = st1.size();
int fst[sz1];
for(int i=0; i< sz1; i++)fst[i]=st1[i];
while(nscd.size()>1){
int sz = nscd.size()/2;
int scd[sz];
for(int i=0; i< sz; i++)scd[i]=nscd[i];
if(query(sz1, sz, fst, scd)){
while(nscd.size()>sz)nscd.pop_back();
}
else{
reverse(nscd.begin(), nscd.end());
for(int i=0; i<sz; i++)nscd.pop_back();
}
}
int scd[1] = {nscd[0]};
vector<int> nfst = st1;
while(nfst.size()>1){
int sz=nfst.size()/2;
int fst[sz];
for(int i=0; i< sz; i++)fst[i]=nfst[i];
if(query(sz, 1, fst, scd)){
while(nfst.size()>sz)nfst.pop_back();
}
else{
reverse(nfst.begin(), nfst.end());
for(int i=0; i< sz; i++)nfst.pop_back();
}
}
setRoad(nfst[0], nscd[0]);
merge(nfst[0], nscd[0]);
}
}
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int k=0; k<a.size(); k++){
| ~^~~~~~~~~
icc.cpp:82:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
82 | while(nscd.size()>sz)nscd.pop_back();
| ~~~~~~~~~~~^~~
icc.cpp:96:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
96 | while(nfst.size()>sz)nfst.pop_back();
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
600 KB |
Ok! 102 queries used. |
2 |
Correct |
4 ms |
604 KB |
Ok! 101 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
604 KB |
Ok! 563 queries used. |
2 |
Correct |
29 ms |
600 KB |
Ok! 694 queries used. |
3 |
Correct |
29 ms |
600 KB |
Ok! 686 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
620 KB |
Ok! 1444 queries used. |
2 |
Correct |
106 ms |
604 KB |
Ok! 1705 queries used. |
3 |
Correct |
79 ms |
624 KB |
Ok! 1632 queries used. |
4 |
Correct |
78 ms |
604 KB |
Ok! 1588 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
632 KB |
Ok! 1627 queries used. |
2 |
Correct |
79 ms |
856 KB |
Ok! 1623 queries used. |
3 |
Correct |
98 ms |
800 KB |
Ok! 1652 queries used. |
4 |
Correct |
74 ms |
604 KB |
Ok! 1539 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
628 KB |
Ok! 1652 queries used. |
2 |
Correct |
82 ms |
640 KB |
Ok! 1652 queries used. |
3 |
Correct |
89 ms |
620 KB |
Ok! 1685 queries used. |
4 |
Correct |
82 ms |
600 KB |
Ok! 1668 queries used. |
5 |
Correct |
76 ms |
624 KB |
Ok! 1539 queries used. |
6 |
Correct |
79 ms |
600 KB |
Ok! 1588 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
80 ms |
624 KB |
Too many queries! 1652 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |