# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
585725 |
2022-06-29T09:11:48 Z |
박상훈(#8384) |
ICC (CEOI16_icc) |
C++14 |
|
140 ms |
612 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){
_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);
}
}
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();
int k = 0;
for (;;k++){
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! 94 queries used. |
2 |
Correct |
5 ms |
468 KB |
Ok! 101 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
496 KB |
Ok! 541 queries used. |
2 |
Correct |
38 ms |
468 KB |
Ok! 694 queries used. |
3 |
Correct |
48 ms |
468 KB |
Ok! 681 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
492 KB |
Ok! 1456 queries used. |
2 |
Correct |
120 ms |
500 KB |
Ok! 1704 queries used. |
3 |
Correct |
115 ms |
612 KB |
Ok! 1584 queries used. |
4 |
Correct |
121 ms |
500 KB |
Ok! 1522 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
496 KB |
Ok! 1525 queries used. |
2 |
Correct |
113 ms |
500 KB |
Ok! 1472 queries used. |
3 |
Correct |
121 ms |
504 KB |
Ok! 1614 queries used. |
4 |
Correct |
117 ms |
488 KB |
Ok! 1526 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
484 KB |
Ok! 1615 queries used. |
2 |
Correct |
140 ms |
508 KB |
Ok! 1614 queries used. |
3 |
Correct |
132 ms |
484 KB |
Ok! 1614 queries used. |
4 |
Correct |
121 ms |
496 KB |
Ok! 1630 queries used. |
5 |
Correct |
116 ms |
492 KB |
Ok! 1504 queries used. |
6 |
Correct |
116 ms |
504 KB |
Ok! 1562 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
484 KB |
Ok! 1614 queries used. |
2 |
Incorrect |
124 ms |
516 KB |
Too many queries! 1704 out of 1625 |
3 |
Halted |
0 ms |
0 KB |
- |