# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
585731 |
2022-06-29T09:16:31 Z |
박상훈(#8384) |
ICC (CEOI16_icc) |
C++14 |
|
126 ms |
620 KB |
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct DSU{
int path[111];
void init(int n){for (int i=1;i<=n;i++) path[i] = i;}
int find(int s){
if (s==path[s]) return s;
return path[s] = find(path[s]);
}
void merge(int s, int v){
s = find(s), v = find(v);
if (s==v) return;
path[s] = v;
}
}dsu;
int A[111], B[111];
int Q(vector<int>::iterator a1, vector<int>::iterator a2, vector<int>::iterator b1, vector<int>::iterator b2){
int sa = a2 - a1, sb = b2 - b1;
for (int i=0;i<sa;i++) A[i] = *(a1+i);
for (int i=0;i<sb;i++) B[i] = *(b1+i);
return query(sa, sb, A, B);
}
vector<int> _A, _B, V[111];
int myquery(int mx, int k, bool flag = 0){
_A.clear(), _B.clear();
for (int i=0;i<mx;i++){
if (i&(1<<k)){
for (auto &x:V[i]) _B.push_back(x);
}
else{
for (auto &x:V[i]) _A.push_back(x);
}
}
if (flag) return 1;
return Q(_A.begin(), _A.end(), _B.begin(), _B.end());
}
int _search(vector<int> A, vector<int> B){
int l = 0, r = (int)A.size()-2, ans = (int)A.size()-1;
while(l<=r){
int m = (l+r)>>1;
if (Q(A.begin(), A.begin()+m+1, B.begin(), B.end())) ans = m, r = m-1;
else l = m+1;
}
return A[ans];
}
void run(int n){
dsu.init(n);
for (int z=0;z<n-1;z++){
vector<int> idx;
for (int i=1;i<=n;i++) idx.push_back(dsu.find(i));
sort(idx.begin(), idx.end());
idx.erase(unique(idx.begin(), idx.end()), idx.end());
for (int i=0;i<=n;i++) V[i].clear();
for (int i=1;i<=n;i++) V[lower_bound(idx.begin(), idx.end(), dsu.find(i)) - idx.begin()].push_back(i);
int mx = idx.size();
vector<int> K;
mt19937 seed(1557);
for (int k=0;(1<<k)<mx;k++) K.push_back(k);
shuffle(K.begin(), K.end(), seed);
int k;
for (auto &kk:K){
k = kk;
if (kk==K.back()) {myquery(mx, k, 1); break;}
if (myquery(mx, k)) break;
}
int x = _search(_A, _B);
int y = _search(_B, {x});
setRoad(x, y);
dsu.merge(x, y);
}
}
//int main(){}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Ok! 101 queries used. |
2 |
Correct |
5 ms |
468 KB |
Ok! 100 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
504 KB |
Ok! 549 queries used. |
2 |
Correct |
37 ms |
468 KB |
Ok! 648 queries used. |
3 |
Correct |
31 ms |
504 KB |
Ok! 645 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
512 KB |
Ok! 1430 queries used. |
2 |
Correct |
106 ms |
516 KB |
Ok! 1606 queries used. |
3 |
Correct |
126 ms |
508 KB |
Ok! 1553 queries used. |
4 |
Correct |
104 ms |
488 KB |
Ok! 1536 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
516 KB |
Ok! 1517 queries used. |
2 |
Correct |
108 ms |
492 KB |
Ok! 1544 queries used. |
3 |
Correct |
110 ms |
512 KB |
Ok! 1563 queries used. |
4 |
Correct |
113 ms |
468 KB |
Ok! 1470 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
496 KB |
Ok! 1569 queries used. |
2 |
Correct |
101 ms |
500 KB |
Ok! 1571 queries used. |
3 |
Correct |
102 ms |
492 KB |
Ok! 1585 queries used. |
4 |
Correct |
101 ms |
468 KB |
Ok! 1576 queries used. |
5 |
Correct |
119 ms |
496 KB |
Ok! 1494 queries used. |
6 |
Correct |
111 ms |
500 KB |
Ok! 1577 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
500 KB |
Ok! 1581 queries used. |
2 |
Correct |
108 ms |
620 KB |
Ok! 1572 queries used. |