QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#363261 | #8505. Almost Aligned | ucup-team3215# | WA | 384ms | 34360kb | C++23 | 4.3kb | 2024-03-23 20:08:25 | 2024-03-23 20:08:25 |
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 = 1e20 + 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) {
if (count({k, m, 0, id}))return;
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;
}
auto operator<=>(const rat &) const = default;
};
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;
for (ll i = 0; auto [x, y, vx, vy]: a) {
z.add(vx, x, i++);
}
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;
for (ll i = 0; auto [x, y, vx, vy]: a) {
z.add(-vx, -x, i++);
}
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;
for (ll i = 0; auto [x, y, vx, vy]: a) {
z.add(vy, y, i++);
}
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;
for (ll i = 0; auto [x, y, vx, vy]: a) {
z.add(-vy, -y, i++);
}
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;
array<point, 4> cur;
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;
// 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);
}
res = min(res, (mxX - mnX) * (mxY - mnY));
}
cout << fixed << setprecision(20);
cout << res;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 4084kb
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: 4076kb
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: 0ms
memory: 3848kb
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: 3980kb
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: 384ms
memory: 34360kb
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:
2261287233698.57317018508911132812
result:
wrong answer 1st numbers differ - expected: '3999996000000.0000000', found: '2261287233698.5732422', error = '0.4346776'