# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
585729 |
2022-06-29T09:14:20 Z |
박상훈(#8384) |
ICC (CEOI16_icc) |
C++14 |
|
134 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();
vector<int> K;
mt19937 seed(324234);
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 (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! 96 queries used. |
2 |
Correct |
5 ms |
496 KB |
Ok! 97 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
484 KB |
Ok! 537 queries used. |
2 |
Correct |
38 ms |
504 KB |
Ok! 694 queries used. |
3 |
Correct |
39 ms |
480 KB |
Ok! 678 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
492 KB |
Ok! 1409 queries used. |
2 |
Correct |
122 ms |
512 KB |
Ok! 1704 queries used. |
3 |
Correct |
129 ms |
500 KB |
Ok! 1583 queries used. |
4 |
Correct |
134 ms |
492 KB |
Ok! 1512 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
492 KB |
Ok! 1545 queries used. |
2 |
Correct |
118 ms |
468 KB |
Ok! 1511 queries used. |
3 |
Correct |
115 ms |
500 KB |
Ok! 1615 queries used. |
4 |
Correct |
120 ms |
612 KB |
Ok! 1483 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
508 KB |
Ok! 1618 queries used. |
2 |
Correct |
133 ms |
504 KB |
Ok! 1615 queries used. |
3 |
Correct |
123 ms |
492 KB |
Ok! 1615 queries used. |
4 |
Correct |
119 ms |
504 KB |
Ok! 1623 queries used. |
5 |
Correct |
111 ms |
492 KB |
Ok! 1457 queries used. |
6 |
Correct |
118 ms |
468 KB |
Ok! 1567 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
468 KB |
Ok! 1615 queries used. |
2 |
Incorrect |
133 ms |
492 KB |
Too many queries! 1695 out of 1625 |
3 |
Halted |
0 ms |
0 KB |
- |