QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387347 | #5111. Take On Meme | ucup-team1209# | WA | 14ms | 4904kb | C++20 | 3.4kb | 2024-04-12 13:55:24 | 2024-04-12 13:55:24 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const int mod = 998244353;
using pr = std::pair<int, int>;
int n;
struct p2 {
int x, y;
};
p2 operator + (p2 x, p2 y) { return {x.x + y.x, x.y + y.y}; }
p2 operator - (p2 x, p2 y) { return {x.x - y.x, x.y - y.y}; }
ll operator * (p2 x, p2 y) {
return (ll) x.x * y.y - (ll) x.y * y.x;
}
bool operator < (const p2 & x, const p2 & y) {
if(x.y != y.y) return x.y < y.y;
return x.x < y.x;
}
using hull = std::vector<p2>;
int half(p2 x) {
return x.y < 0 || (x.y == 0 && x.x <= 0);
}
int cmp(p2 a, p2 b) {
return half(a) == half(b) ? a * b > 0 : half(b);
}
hull conv(hull a, hull b) {
rotate(a.begin(), min_element(a.begin(), a.end()), a.end());
rotate(b.begin(), min_element(b.begin(), b.end()), b.end());
std::vector<p2> x(a.size() - 1);
std::vector<p2> y(b.size() - 1);
for(int i = 0;i + 1 < (int) a.size();++i) {
x[i] = a[i + 1] - a[i];
}
for(int i = 0;i + 1 < (int) b.size();++i) {
y[i] = b[i + 1] - b[i];
}
std::vector<p2> ans(a.size() + b.size() - 1);
merge(x.begin(), x.end(), y.begin(), y.end(), ans.begin() + 1, cmp);
ans[0] = a[0] + b[0];
for(int i = 1;i < (int) ans.size();++i) {
ans[i] = ans[i - 1] + ans[i];
}
for(int i = 2;i < (int) ans.size();++i) {
// assert((ans[i - 1] - ans[0]) * (ans[i] - ans[0]) >= 0);
// assert((ans[i - 1] - ans[i - 2]) * (ans[i] - ans[i - 2]) >= 0);
}
return ans;
}
ll cross(p2 x, p2 y, p2 z) {
return (y - x) * (z - x);
}
hull un(hull o, hull b) {
o.insert(o.end(), b.begin(), b.end());
sort(o.begin(), o.end(), [&](p2 x, p2 y) {
return x.x == y.x ? x.y < y.y : x.x < y.x;
});
o.erase(unique(o.begin(), o.end(), [](p2 x, p2 y) {
return x.x == y.x && x.y == y.y;
}), o.end());
std::vector<p2> s;
for(int i = 0;i < (int) o.size();++i) {
for(;s.size() >= 2 && cross(s.rbegin()[1], s.back(), o[i]) <= 0;) {
s.pop_back();
}
s.push_back(o[i]);
}
for(int i = o.size() - 2, t = s.size();i >= 0;--i) {
for(;s.size() > t && cross(s.rbegin()[1], s.back(), o[i]) <= 0;) {
s.pop_back();
}
s.push_back(o[i]);
}
if(s.size() > 1) s.pop_back();
return s;
}
const int N = 1e4 + 10;
std::vector<int> son[N];
p2 a[N];
std::vector<p2> get(int x) {
if(son[x].empty()) {
return {a[x]};
}
std::vector<std::vector<p2>> v;
for(int i : son[x]) {
v.push_back(get(i));
}
auto s = [&](auto s, int l, int r) {
if(l + 1 == r) {
auto A = v[l], B = v[l];
for(auto & [x, y] : A) x *= -1, y *= -1;
return std::make_pair(A, B);
}
int mid = (l + r) >> 1;
auto [a0, a1] = s(s, l, mid);
auto [b0, b1] = s(s, mid, r);
return std::make_pair(
conv(a0, b0),
un(conv(a0, b1), conv(a1, b0))
);
};
auto [a, b] = s(s, 0, v.size());
return b;
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
// std::mt19937 gen;
// std::vector<p2> A, B;
// for(int i = 0;i < 20;++i) {
// A.push_back({gen()%100,gen()%100});
// B.push_back({gen()%100,gen()%100});
// }
// A = un(A, {});
// B = un(B, {});
// auto C = conv(A, B);
cin >> n;
for(int i = 1;i <= n;++i) {
int k; cin >> k;
son[i].resize(k);
for(int & x : son[i]) cin >> x;
if(!k) cin >> a[i].x >> a[i].y;
}
auto conv = get(1);
ll ans = 0;
for(auto [u, v] : conv) {
ans = std::max(ans, (ll) u * u + (ll) v * v);
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
5 4 2 3 4 5 0 2 -2 0 1 3 0 4 -6 0 -18 5
output:
725
result:
ok single line: '725'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
5 2 2 3 2 4 5 0 1 5 0 -4 -6 0 -1 7
output:
340
result:
ok single line: '340'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
18 3 4 3 2 2 5 6 3 7 9 8 3 10 11 12 0 4 -1 0 18 49 0 -2 10 2 13 14 0 -5 6 0 5 8 4 15 16 17 18 0 17 3 0 3 -9 0 -7 -1 0 14 -33 0 -23 11 0 11 14 0 2 19
output:
26269
result:
ok single line: '26269'
Test #4:
score: -100
Wrong Answer
time: 14ms
memory: 4904kb
input:
10000 59 2 171 340 509 678 847 1016 1185 1382 1551 1720 1889 2058 2227 2396 2565 2734 2903 3072 3241 3410 3579 3748 3917 4086 4255 4424 4593 4762 4931 5100 5269 5438 5607 5776 5945 6114 6283 6452 6621 6790 6959 7128 7297 7466 7635 7804 7973 8142 8311 8480 8649 8818 8987 9156 9325 9494 9663 9832 2 3 ...
output:
4596994535080
result:
wrong answer 1st lines differ - expected: '4893524000116', found: '4596994535080'