#include<bits/stdc++.h>
#include "icc.h"
using namespace std;
#ifndef d
#define d(...)
#endif
#define st first
#define nd second
#define pb push_back
#define siz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
typedef long long LL;
typedef long double LD;
constexpr int INF=1e9+7;
constexpr LL INFL=1e18;
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.st << "," << P.nd << ")";
}
constexpr int maxn = 105;
using Component = vector<int>;
int n;
vector<Component> C;
vector<int> get_vertices(vector<int>& ind) {
vector<int> ret;
for(auto i:ind)
for(auto x:C[i])
ret.push_back(x);
return ret;
}
int make_query(vector<int> l, vector<int> r) {
return query(l.size(), r.size(), l.data(), r.data());
}
void merge(int a, int b) {
auto f = [&](int x) {
for(size_t i=0; i<C.size(); i++)
if(find(all(C[i]), x) != C[i].end())
return i;
return C.size();
};
a = f(a), b = f(b);
for(auto x:C[b])
C[a].push_back(x);
C[b] = C.back();
C.pop_back();
}
void run(int _n) {
n = _n;
for(int i=1; i<=n; i++) {
C.push_back({i});
}
mt19937 rng(time(0));
for(int _=0; _<n-1; _++) {
vector<int> L, R;
while(true) {
L.clear(), R.clear();
for(size_t i=0; i<C.size(); i++)
(rng() & 1 ? L : R).push_back(i);
if(make_query(get_vertices(L), get_vertices(R))) break;
}
L = get_vertices(L);
R = get_vertices(R);
auto it = L.begin(), it2 = L.end();
while(it + 1 != it2) {
auto s = it + distance(it, it2) / 2;
if(make_query(vector<int>(it, s), R))
it2 = s;
else
it = s;
}
int a = *it;
it = R.begin(), it2 = R.end();
while(it + 1 != it2) {
auto s = it + distance(it, it2) / 2;
if(make_query(vector<int>(it, s), L))
it2 = s;
else
it = s;
}
int b = *it;
setRoad(a, b);
merge(a, b);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
512 KB |
Ok! 114 queries used. |
2 |
Correct |
10 ms |
640 KB |
Ok! 105 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
572 KB |
Ok! 555 queries used. |
2 |
Correct |
62 ms |
576 KB |
Ok! 849 queries used. |
3 |
Correct |
73 ms |
512 KB |
Ok! 836 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
572 KB |
Ok! 1532 queries used. |
2 |
Correct |
199 ms |
604 KB |
Ok! 2175 queries used. |
3 |
Correct |
157 ms |
556 KB |
Ok! 1759 queries used. |
4 |
Correct |
185 ms |
632 KB |
Ok! 1760 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
512 KB |
Ok! 1655 queries used. |
2 |
Correct |
155 ms |
512 KB |
Ok! 1698 queries used. |
3 |
Correct |
162 ms |
632 KB |
Ok! 1898 queries used. |
4 |
Correct |
140 ms |
632 KB |
Ok! 1608 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
205 ms |
604 KB |
Too many queries! 1884 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
184 ms |
608 KB |
Too many queries! 1996 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |