QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361851 | #5111. Take On Meme | JerryTcl | WA | 0ms | 4072kb | C++20 | 2.5kb | 2024-03-23 13:25:09 | 2024-03-23 13:25:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
template<typename T1, typename T2> struct Pair {
T1 x; T2 y; Pair(T1 X = T1(), T2 Y = T2()) : x(X), y(Y) {}
Pair operator + (const Pair o) const { return Pair(x + o.x, y + o.y); }
template<typename U> Pair operator * (const U o) const { return Pair(x * o, y * o); }
template<typename U> friend Pair operator * (const U p, const Pair q) { return q * p; }
Pair operator - () const { return (*this) * -1; }
Pair operator - (const Pair o) const { return (*this) + (-o); }
void operator += (const Pair o) { (*this) = (*this) + o; }
void operator -= (const Pair o) { (*this) = (*this) - o; }
friend istream &operator >> (istream &is, Pair &o) { return is >> o.x >> o.y; }
friend ostream &operator << (ostream &os, const Pair o) { return os << "(" << o.x << ", " << o.y << ")"; }
};
typedef Pair<int, int> Pnt, Vec; typedef const Pnt cPnt, cVec;
inline Vec Rot90(cVec p) { return Pnt(-p.y, p.x); }
inline int64 Dot(cVec a, cVec b) { return 1ll * a.x * b.x + 1ll * a.y * b.y; }
inline int64 Cro(cVec a, cVec b) { return 1ll * a.x * b.y - 1ll * a.y * b.x; }
inline int64 Len2(cVec a) { return Dot(a, a); }
inline int64 Lft(cPnt p, cPnt a, cPnt b) { return Cro(p - a, b - a) < 0; }
template<typename Fp> void Work(cPnt A, cPnt B, const Fp f) {
cPnt C = f(Rot90(B - A)); if(Lft(C, A, B)) Work(A, C, f), Work(C, B, f); }
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n; vector<Vec> val(n);
vector<vector<int>> son(n); int64 ans = 0;
for(int i = 0, s; i < n; ++i) {
cin >> s; if(!s) { cin >> val[i]; continue; }
son[i].resize(s); for(int &v : son[i]) cin >> v, --v;
}
const auto solve = [&](cVec dir) {
const auto &dfs = [&](auto &&self, int x) -> Pair<Pnt, Pnt> {
if(son[x].empty()) return {val[x], val[x]};
Vec smn, smx; Pair<int64, Vec> mn(LLONG_MAX), mx(LLONG_MIN);
for(const int y : son[x]) {
const auto [fmn, fmx] = self(self, y); smn += fmn, smx += fmx;
const Vec v = fmn + fmx; const int64 w = Dot(v, dir);
if(mn.x > w) mn = {w, v}; if(mx.x < w) mx = {w, v};
}
return {mn.y - smx, mx.y - smn};
};
const auto [fmn, fmx] = dfs(dfs, 0);
ans = max(ans, Len2(fmx.y)); return fmx.y;
};
const Pnt L = solve(Vec(-1, 0)), R = solve(Vec(1, 0));
Work(L, R, solve), Work(R, L, solve), printf("%lld", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4072kb
input:
5 4 2 3 4 5 0 2 -2 0 1 3 0 4 -6 0 -18 5
output:
144
result:
wrong answer 1st lines differ - expected: '725', found: '144'