QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#363302 | #8505. Almost Aligned | ucup-team3215# | WA | 3070ms | 83860kb | C++23 | 5.4kb | 2024-03-23 20:54:19 | 2024-03-23 20:54:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
constexpr ld INF = 1e30 + 1;
struct point {
ll x, y, vx, vy;
pair<ld, ld> eval(ld t) {
return {x + t * vx, y + t * vy};
}
};
struct Line {
mutable ll k, m, p, id;
bool operator<(const Line &o) const {
return k < o.k;
}
bool operator<(ll x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
static constexpr ll inf = LLONG_MAX;
ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) return x->p = inf, 0;
if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
else x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(ll k, ll m, ll id) {
assert(find({k, 0, 0, 0}) == end());
auto z = insert({k, m, 0, id}), y = z++, x = y;
while (isect(y, z)) z = erase(z);
if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
};
struct rat {
ll x, y;
rat(ll x, ll y) : x(x), y(y) {
ll g = __gcd(x, y);
x /= g;
y /= g;
assert(x * y >= 0);
}
bool operator<(const rat &o) const {
return (__int128) x * o.y < (__int128) y * o.x;
}
};
int main() {
cin.tie(0)->sync_with_stdio(false);
ll n;
cin >> n;
vector<point> a(n);
for (auto &[x, y, vx, vy]: a)cin >> x >> y >> vx >> vy;
map<rat, vector<pair<point, ll>>> mp;
{
LineContainer z;
map<ll, pl> q;
for (ll i = 0; auto [x, y, vx, vy]: a) {
if (!q.count(vx) || q[vx].first < x) {
q[vx] = {x, i};
}
++i;
}
for (auto [vx, t]: q) {
z.add(vx, t.first, t.second);
}
mp[rat(0, 1)].push_back({a[z.begin()->id], 0});
auto last = a[z.begin()->id];
z.erase(z.begin());
while (!z.empty()) {
auto it = a[z.begin()->id];
z.erase(z.begin());
assert(it.vx > last.vx);
mp[rat(abs(last.x - it.x), abs(it.vx - last.vx))].push_back({it, 0});
last = it;
}
}
{
LineContainer z;
map<ll, pl> q;
for (ll i = 0; auto [x, y, vx, vy]: a) {
x = -x, vx = -vx;
if (!q.count(vx) || q[vx].first < x) {
q[vx] = {x, i};
}
++i;
}
for (auto [vx, t]: q) {
z.add(vx, t.first, t.second);
}
mp[rat(0, 1)].push_back({a[z.begin()->id], 1});
auto last = a[z.begin()->id];
z.erase(z.begin());
while (!z.empty()) {
auto it = a[z.begin()->id];
z.erase(z.begin());
assert(it.vx < last.vx);
mp[rat(abs(it.x - last.x), abs(last.vx - it.vx))].push_back({it, 1});
last = it;
}
}
{
LineContainer z;
map<ll, pl> q;
for (ll i = 0; auto [x, y, vx, vy]: a) {
if (!q.count(vy) || q[vy].first < y) {
q[vy] = {y, i};
}
++i;
}
for (auto [vx, t]: q) {
z.add(vx, t.first, t.second);
}
mp[rat(0, 1)].push_back({a[z.begin()->id], 2});
auto last = a[z.begin()->id];
z.erase(z.begin());
while (!z.empty()) {
auto it = a[z.begin()->id];
z.erase(z.begin());
assert(it.vy > last.vy);
mp[rat(abs(last.y - it.y), abs(it.vy - last.vy))].push_back({it, 2});
last = it;
}
}
{
LineContainer z;
map<ll, pl> q;
for (ll i = 0; auto [x, y, vx, vy]: a) {
vy = -vy, y = -y;
if (!q.count(vy) || q[vy].first < y) {
q[vy] = {y, i};
}
++i;
}
for (auto [vx, t]: q) {
z.add(vx, t.first, t.second);
}
mp[rat(0, 1)].push_back({a[z.begin()->id], 3});
auto last = a[z.begin()->id];
z.erase(z.begin());
while (!z.empty()) {
auto it = a[z.begin()->id];
z.erase(z.begin());
assert(it.vy < last.vy);
mp[rat(abs(it.y - last.y), abs(last.vy - it.vy))].push_back({it, 3});
last = it;
}
}
ld res = INF * INF;
array<point, 4> cur{};
ld last = -1;
for (const auto &[t, v]: mp) {
for (auto [p, i]: v) {
cur[i] = p;
}
ld mnX = INF, mxX = -INF;
ld mnY = INF, mxY = -INF;
ld timer = (ld) t.x / t.y;
assert(timer > last);
last = timer;
// cout << timer << endl;
for (auto p: cur) {
// cout << p.x << " " << p.y << " " << p.vx << " " << p.vy << endl;
auto [x, y] = p.eval(timer);
mnX = min(mnX, x);
mnY = min(mnY, y);
mxX = max(mxX, x);
mxY = max(mxY, y);
}
// cout << mnX << " " << mxX << " " << mnY << " " << mxY << endl;
res = min(res, (mxX - mnX) * (mxY - mnY));
}
cout << fixed << setprecision(20);
cout << res;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4052kb
input:
4 0 0 10 10 0 0 10 10 10 10 -10 -10 10 0 -20 0
output:
22.22222222222222222203
result:
ok found '22.222222222', expected '22.222222222', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
3 0 -1 0 2 1 1 1 1 -1 1 -1 1
output:
0.00000000000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
3 0 -1 0 -2 1 1 1 1 -1 1 -1 1
output:
4.00000000000000000000
result:
ok found '4.000000000', expected '4.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3960kb
input:
1 0 0 0 0
output:
0.00000000000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
4 1000000 1000000 -1 -1000000 1000000 -1000000 -1000000 1 -1000000 -1000000 1 1000000 -1000000 1000000 1000000 -1
output:
3999984000031.99995207786560058594
result:
ok found '3999984000032.000000000', expected '3999984000032.000000000', error '0.000000000'
Test #6:
score: -100
Wrong Answer
time: 3070ms
memory: 83860kb
input:
1000000 -871226 486657 -467526 31395 -65837 846554 469710 -907814 927993 -45099 713462 -276539 261942 483255 746021 811070 63449 -779486 588838 -413687 812070 -87868 -813499 -420768 112521 -622607 -832012 921368 -182120 517379 -401743 -837524 -685985 337832 643014 135144 12895 326935 -495720 930620 ...
output:
2090252979049.89351832866668701172
result:
wrong answer 1st numbers differ - expected: '3999996000000.0000000', found: '2090252979049.8935547', error = '0.4774362'