#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, ind(C.size());
iota(all(ind), 0);
int half = ind.size() / 2;
while(true) {
shuffle(all(ind), rng);
L.assign(ind.begin(), ind.begin() + half);
R.assign(ind.begin() + half, ind.end());
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 |
8 ms |
512 KB |
Ok! 100 queries used. |
2 |
Correct |
11 ms |
512 KB |
Ok! 103 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
512 KB |
Ok! 529 queries used. |
2 |
Correct |
51 ms |
564 KB |
Ok! 824 queries used. |
3 |
Correct |
56 ms |
512 KB |
Ok! 791 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
568 KB |
Ok! 1514 queries used. |
2 |
Correct |
190 ms |
604 KB |
Ok! 2150 queries used. |
3 |
Correct |
136 ms |
512 KB |
Ok! 1690 queries used. |
4 |
Correct |
180 ms |
604 KB |
Ok! 1721 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
636 KB |
Ok! 1630 queries used. |
2 |
Correct |
134 ms |
632 KB |
Ok! 1654 queries used. |
3 |
Correct |
159 ms |
604 KB |
Ok! 1870 queries used. |
4 |
Correct |
125 ms |
636 KB |
Ok! 1592 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
156 ms |
632 KB |
Too many queries! 1895 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
155 ms |
512 KB |
Too many queries! 1924 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |