QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215789 | #5111. Take On Meme | kuroni | WA | 1ms | 3556kb | C++14 | 3.7kb | 2023-10-15 13:38:11 | 2023-10-15 13:38:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x=0, T y=0) : x(x), y(y) {}
bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
P operator+(P p) const { return P(x+p.x, y+p.y); }
P operator-(P p) const { return P(x-p.x, y-p.y); }
P operator*(T d) const { return P(x*d, y*d); }
P operator/(T d) const { return P(x/d, y/d); }
T dot(P p) const { return x*p.x + y*p.y; }
T cross(P p) const { return x*p.y - y*p.x; }
T cross(P a, P b) const { return (a-*this).cross(b-*this); }
T dist2() const { return x*x + y*y; }
double dist() const { return sqrt((double)dist2()); }
// angle to x-axis in interval [-pi, pi]
double angle() const { return atan2(y, x); }
P unit() const { return *this/dist(); } // makes dist()=1
P perp() const { return P(-y, x); } // rotates +90 degrees
P normal() const { return perp().unit(); }
// returns point rotated 'a' radians ccw around the origin
P rotate(double a) const {
return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
friend ostream& operator<<(ostream& os, P p) {
return os << "(" << p.x << "," << p.y << ")"; }
};
typedef Point<ll> P;
vector<P> minkowskiSum(vector<vector<P>> hs) {
auto cmp = [](P a, P b) {
return make_pair(a.x < 0 || a.x == 0 && a.y < 0, a.y * (ll)b.x)
< make_pair(b.x < 0 || b.x == 0 && b.y < 0, a.x * (ll)b.y);
};
typedef tuple<P, int, int> T;
auto cmp_tup = [&cmp](T a, T b) {
auto& [pa, ja, ia] = a;
auto& [pb, jb, ib] = b;
if (cmp(pa, pb)) return false;
if (cmp(pb, pa)) return true;
return make_pair(ja, ia) < make_pair(jb, ib);
};
priority_queue<T, vector<T>, decltype(cmp_tup)> pq(cmp_tup);
P cur = P();
int s = 0, t = 0;
rep(i, 0, sz(hs)) {
auto& v = hs[i];
rotate(begin(v), min_element(all(v)), end(v));
if (sz(v) > 1) pq.push({v[1] - v[0], 0, i}), s += sz(v);
cur = cur + v[0];
}
vector<P> h(s + 1);
for (h[t++] = cur; sz(pq);) {
auto [p, j, i] = pq.top(); pq.pop();
t -= (t >= 2 && !cmp(h[t - 1] - h[t - 2], p));
h[t++] = (cur = cur + p);
auto& v = hs[i];
if (++j < sz(v)) pq.push({v[(j + 1) % sz(v)] - v[j], j, i});
}
return {h.begin(), h.begin() + t - (t >= 2 && h[0] == h[t - 1])};
}
vector<P> convexHull(vector<P> pts) {
if (sz(pts) <= 1) return pts;
sort(all(pts));
vector<P> h(sz(pts)+1);
int s = 0, t = 0;
for (int it = 2; it--; s = --t, reverse(all(pts)))
for (P p : pts) {
while (t >= s + 2 && h[t-2].cross(h[t-1], p) <= 0) t--;
h[t++] = p;
}
return {h.begin(), h.begin() + t - (t == 2 && h[0] == h[1])};
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n; cin >> n;
vector<vector<int>> adj(n);
vector<vector<P>> pts(n);
for (int i = 0; i < n; i++) {
int k; cin >> k;
if (k == 0) {
int x, y; cin >> x >> y;
pts[i].push_back(P(x, y));
} else {
while (k--) {
int v; cin >> v; v--;
adj[i].push_back(v);
}
}
}
for (int u = n - 1; u >= 0; u--) {
if (adj[u].empty()) {
continue;
}
vector<vector<P>> cur;
for (int v : adj[u]) {
cur.push_back(move(pts[v]));
}
for (auto& poly : cur) {
for (P& p : poly) {
p = P(0, 0) - p;
}
auto sum = minkowskiSum(cur);
pts[u].insert(pts[u].end(), sum.begin(), sum.end());
for (P& p : poly) {
p = P(0, 0) - p;
}
}
}
ll ans = 0;
for (P& p : pts[0]) {
ans = max(ans, p.dist2());
}
cout << ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3488kb
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: 3492kb
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: -100
Wrong Answer
time: 0ms
memory: 3556kb
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:
25857
result:
wrong answer 1st lines differ - expected: '26269', found: '25857'