# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
229327 |
2020-05-04T08:28:38 Z |
islingr |
ICC (CEOI16_icc) |
C++14 |
|
160 ms |
760 KB |
#include <icc.h>
#include <iostream>
#include <vector>
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define eb(x...) emplace_back(x)
#define sz(x) int((x).size())
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
vector<vi> comp;
bool query(vi &a, vi &b) {
return query(sz(a), sz(b), a.data(), b.data());
}
bool query_comp(vi &a, vi &b) {
vi x, y;
for (int c : a) for (int v : comp[c]) x.eb(v);
for (int c : b) for (int v : comp[c]) y.eb(v);
return query(x, y);
}
void merge(int a, int b) {
copy(begin(comp[b]), end(comp[b]), back_inserter(comp[a]));
comp.erase(begin(comp) + b);
}
pii dnc(vi a, vi b) {
if (sz(a) < sz(b)) swap(a, b); // sz(b) <= sz(a)
if (sz(a) == 1 && sz(b) == 1) return {a[0], b[0]};
int mid = (sz(a) + 1)/ 2;
vi l(begin(a), begin(a) + mid), r(begin(a) + mid, end(a));
if (query(l, b)) return dnc(l, b);
return dnc(r, b);
}
void run(int n) {
rep(i, 0, n) comp.eb(vi{i + 1});
rep(i, 1, n) {
int axb = 0;
for (int j = 0; (1 << j) <= sz(comp); ++j) {
vi a, b;
rep(k, 0, sz(comp))
if (k & 1 << j) a.eb(k);
else b.eb(k);
if (query_comp(a, b))
axb |= 1 << j;
}
int x; for (x = 0; ~axb & 1 << x; ++x);
int l = 1 << x, r = 0;
for (int j = 0; (1 << j) <= sz(comp); ++j) {
if (j == x) continue;
vi a, b;
if (axb & 1 << j) {
rep(k, 0, sz(comp))
if (k & 1 << x) { if (k & 1 << j) a.eb(k); }
else { if (~k & 1 << j) b.eb(k); }
if (query_comp(a, b)) l |= 1 << j;
else r |= 1 << j;
} else {
rep(k, 0, sz(comp))
if (k & 1 << j) {
if (k & 1 << x) a.eb(k);
else b.eb(k);
}
if (query_comp(a, b)) {
l |= 1 << j;
r |= 1 << j;
}
}
}
pii p = dnc(comp[l], comp[r]);
merge(l, r);
setRoad(p.first, p.second);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
512 KB |
Ok! 123 queries used. |
2 |
Correct |
14 ms |
512 KB |
Ok! 122 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
512 KB |
Ok! 661 queries used. |
2 |
Correct |
41 ms |
512 KB |
Ok! 521 queries used. |
3 |
Correct |
45 ms |
512 KB |
Ok! 547 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
632 KB |
Ok! 1566 queries used. |
2 |
Correct |
131 ms |
632 KB |
Ok! 1241 queries used. |
3 |
Correct |
150 ms |
512 KB |
Ok! 1621 queries used. |
4 |
Correct |
148 ms |
512 KB |
Ok! 1559 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
512 KB |
Ok! 1547 queries used. |
2 |
Correct |
151 ms |
512 KB |
Ok! 1501 queries used. |
3 |
Correct |
144 ms |
632 KB |
Ok! 1412 queries used. |
4 |
Correct |
153 ms |
636 KB |
Ok! 1604 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
512 KB |
Ok! 1429 queries used. |
2 |
Correct |
143 ms |
760 KB |
Ok! 1363 queries used. |
3 |
Correct |
140 ms |
512 KB |
Ok! 1315 queries used. |
4 |
Correct |
146 ms |
512 KB |
Ok! 1491 queries used. |
5 |
Correct |
156 ms |
512 KB |
Ok! 1573 queries used. |
6 |
Correct |
146 ms |
512 KB |
Ok! 1536 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
636 KB |
Ok! 1567 queries used. |
2 |
Correct |
124 ms |
632 KB |
Ok! 1244 queries used. |