QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380141#8505. Almost AlignedinstallbWA 779ms106296kbC++203.6kb2024-04-06 21:10:412024-04-06 21:10:42

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 21:10:42]
  • 评测
  • 测评结果:WA
  • 用时:779ms
  • 内存:106296kb
  • [2024-04-06 21:10:41]
  • 提交

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});
        }
    }
}

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: 100
Accepted
time: 0ms
memory: 75548kb

input:

4
0 0 10 10
0 0 10 10
10 10 -10 -10
10 0 -20 0

output:

22.222222222222229

result:

ok found '22.222222222', expected '22.222222222', error '0.000000000'

Test #2:

score: 0
Accepted
time: 3ms
memory: 75512kb

input:

3
0 -1 0 2
1 1 1 1
-1 1 -1 1

output:

0.000000000000001

result:

ok found '0.000000000', expected '0.000000000', error '0.000000000'

Test #3:

score: 0
Accepted
time: 3ms
memory: 75568kb

input:

3
0 -1 0 -2
1 1 1 1
-1 1 -1 1

output:

4.000000000000000

result:

ok found '4.000000000', expected '4.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 73524kb

input:

1
0 0 0 0

output:

0.000000000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #5:

score: 0
Accepted
time: 3ms
memory: 75580kb

input:

4
1000000 1000000 -1 -1000000
1000000 -1000000 -1000000 1
-1000000 -1000000 1 1000000
-1000000 1000000 1000000 -1

output:

3999984000032.000000000000000

result:

ok found '3999984000032.000000000', expected '3999984000032.000000000', error '0.000000000'

Test #6:

score: -100
Wrong Answer
time: 779ms
memory: 106296kb

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:

763045055268.342529296875000

result:

wrong answer 1st numbers differ - expected: '3999996000000.0000000', found: '763045055268.3425293', error = '0.8092385'