QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380253 | #8505. Almost Aligned | installb | WA | 4ms | 75616kb | C++20 | 3.6kb | 2024-04-06 22:29:12 | 2024-04-06 22:29:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const db eps = 1e-12;
const db pi = acos(-1.0);
const db MX = 4e9;
const int N = 2000005;
int sgn(db x){
if(x > -eps && x < eps) return 0;
if(x > 0) return 1;
return -1;
}
struct point{
db x,y;
point (db _x = 0.0,db _y = 0.0) : x(_x), y(_y) {}
bool operator < (const point &p) const{
if(sgn(x - p.x) == 0) return sgn(y - p.y) < 0;
return x < p.x;
}
};
point operator - (const point &p1,const point &p2){
return point(p1.x - p2.x,p1.y - p2.y);
}
point operator + (const point &p1,const point &p2){
return point(p1.x + p2.x,p1.y + p2.y);
}
point operator * (db x,const point &p){
return point(x * p.x,x * p.y);
}
db dot(point p1,point p2){
return p1.x * p2.x + p1.y * p2.y;
}
db det(point p1,point p2){
return p1.x * p2.y - p2.x * p1.y;
}
int n;
db x[N],y[N],vx[N],vy[N];
point p[N],q[N]; db qt[N]; int m;
vector <pair <point,db> > H[2][2];
vector <db> ti;
void calct(int id,int xy){
vector <point> G;
for(int i = 1;i <= n;i ++){
if(!xy) p[i] = point(vx[i],x[i]);
else p[i] = point(vy[i],y[i]);
}
sort(p + 1,p + 1 + n);
if(!id){
m = 0; q[++ m] = p[1];
for(int i = 2;i <= n;i ++){
while(m > 1 && sgn(det(q[m] - q[m - 1],p[i] - q[m - 1])) >= 0) m --;
q[++ m] = p[i];
}
}
else{
m = 0; q[++ m] = p[1];
for(int i = 2;i <= n;i ++){
while(m > 1 && sgn(det(q[m] - q[m - 1],p[i] - q[m - 1])) <= 0) m --;
q[++ m] = p[i];
}
reverse(q + 1,q + 1 + m);
}
qt[1] = 0.0;
for(int i = 2;i <= m;i ++){
qt[i] = (q[i - 1].y - q[i].y) / (q[i].x - q[i - 1].x);
}
for(int i = 1;i <= m;i ++){
if(qt[i] >= -eps && qt[i] <= MX){
ti.push_back(qt[i]);
H[id][xy].push_back({point(qt[i],qt[i] * q[i].x + q[i].y),q[i].x});
}
}
sort(H[id][xy].begin(),H[id][xy].end());
}
void solve(){
scanf("%d",&n);
for(int i = 1;i <= n;i ++){
scanf("%lf %lf %lf %lf",&x[i],&y[i],&vx[i],&vy[i]);
}
calct(0,0);
calct(1,0);
calct(0,1);
calct(1,1);
ti.push_back(MX);
sort(ti.begin(),ti.end());
ti.erase(unique(ti.begin(),ti.end()),ti.end());
db ans = 1e99;
for(int i = 0;i + 1 < ti.size();i ++){
db l = ti[i],r = ti[i + 1];
auto [xup,xuv] = *(-- upper_bound(H[0][0].begin(),H[0][0].end(),make_pair(point(l,1e22),0.0)));
auto [xdp,xdv] = *(-- upper_bound(H[1][0].begin(),H[1][0].end(),make_pair(point(l,1e22),0.0)));
auto [yup,yuv] = *(-- upper_bound(H[0][1].begin(),H[0][1].end(),make_pair(point(l,1e22),0.0)));
auto [ydp,ydv] = *(-- upper_bound(H[1][1].begin(),H[1][1].end(),make_pair(point(l,1e22),0.0)));
db xdel = xuv - xdv,ydel = yuv - ydv;
db xlen = ((l - xup.x) * xuv + xup.y) - ((l - xdp.x) * xdv + xdp.y);
db ylen = ((l - yup.x) * yuv + yup.y) - ((l - ydp.x) * ydv + ydp.y);
db LL = l;
for(int ti = 1;ti <= 160;ti ++){
db midl = (l + l + r) / 3.0;
db midr = (l + r + r) / 3.0;
db calcl = fabs(xlen + xdel * (midl - LL)) * fabs(ylen + ydel * (midl - LL));
db calcr = fabs(xlen + xdel * (midr - LL)) * fabs(ylen + ydel * (midr - LL));
ans = min(ans,min(calcl,calcr));
if(calcl < calcr) r = midr;
else l = midl;
}
}
cout << fixed << setprecision(15) << ans << '\n';
}
int main(){
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 75616kb
input:
4 0 0 10 10 0 0 10 10 10 10 -10 -10 10 0 -20 0
output:
0.000000000000000
result:
wrong answer 1st numbers differ - expected: '22.2222222', found: '0.0000000', error = '1.0000000'