QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374984#5433. Absolute DifferencehuzhaoyangWA 1ms4080kbC++142.0kb2024-04-02 20:26:182024-04-02 20:26:19

Judging History

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

  • [2024-04-02 20:26:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4080kb
  • [2024-04-02 20:26:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef __int128 LL;
typedef pair<int,int> pii;
const int N=100005;
int n,m;
ll nn,mm;
LL ans;
pii a[N],b[N];
struct Data{
    ll P;LL E;
    Data operator + (const Data &n)const{
        return Data{P+n.P,E+n.E};
    }
    double operator - (const Data &n)const{
        return E*n.P-P*n.E;
    }
}sa,sb,Sa,Sb;
ll sqr(int k){
    return (ll)k*k;
}
LL cube(int k){
    return (LL)k*k*k;
}
LL calc(pii x,pii y){
    if ((!nn)&&(!mm))return 6LL*abs(x.fi-y.fi);
    if ((!nn)||(!mm)){
        if (!mm)swap(x,y);
        if (x.fi<y.fi)return (LL)3*(y.se-y.fi)*(0LL+y.fi+y.se-x.fi-x.fi);
        if (x.fi>y.se)return (LL)3*(y.se-y.fi)*(0LL+x.fi+x.fi-y.fi-y.se);
        return (LL)3*(sqr(x.fi-y.fi)+sqr(y.se-x.fi));
    }
    if (x.fi>y.fi)swap(x,y);
    if (x.se<y.fi)return (LL)3*(x.se-x.fi)*(y.se-y.fi)*(0LL+y.fi+y.se-x.fi-x.se);
    LL s=(LL)3*(y.fi-x.fi)*(y.se-y.fi)*(y.se-x.fi);
    x.fi=y.fi;
    if (x.se>y.se)swap(x,y);
    return s+2*cube(x.se-x.fi)+(LL)3*(x.se-x.fi)*(y.se-x.se)*(y.se-x.fi);
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].fi,&a[i].se);
    for(int i=1;i<=m;i++)scanf("%d%d",&b[i].fi,&b[i].se);
    sort(a+1,a+n+1),sort(b+1,b+m+1);
    for(int i=1;i<=n;i++)nn+=a[i].se-a[i].fi;
    for(int i=1;i<=m;i++)mm+=b[i].se-b[i].fi;
    sa=sb=Sa=Sb=Data{0,0};
    for(int i=1,j=1;(i<=n)||(j<=m);){
        if ((i<=n)&&(j<=m))ans+=calc(a[i],b[j]);
        if ((i<=n)&&((j>m)||(a[i].se<b[j].se))){
            Data o=(nn ? Data{1,6*a[i].fi} : Data{a[i].se-a[i].fi,3*(sqr(a[i].se)-sqr(a[i].fi))});
            i++,ans+=o-sb,sb=sb+Sb,Sa=Sa+o,Sb=Data{0,0};
        }
        else{
            Data o=(mm ? Data{1,6*b[j].fi} : Data{b[j].se-b[j].fi,3*(sqr(b[j].se)-sqr(b[j].fi))});
            j++,ans+=o-sa,sa=sa+Sa,Sb=Sb+o,Sa=Data{0,0};
        }
    }
    printf("%.9f\n",ans/6.0/(nn ? nn : n)/(mm ? mm : m));
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3796kb

input:

1 1
0 1
0 1

output:

0.333333333

result:

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

Test #2:

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

input:

1 1
0 1
1 1

output:

0.500000000

result:

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

Test #3:

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

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666627

result:

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

Test #4:

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

input:

1 1
-1000000000 0
0 1000000000

output:

999999999.999999881

result:

ok found '999999999.999999881', expected '1000000000.000000000', error '0.000000000'

Test #5:

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

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000000

result:

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

Test #6:

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

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.500000000

result:

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

Test #7:

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

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999.000000000

result:

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

Test #8:

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

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000.000000000

result:

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

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 3804kb

input:

1000 1000
-2175 -2174
-1068 -1065
-1721 -1718
777 834
1162 1169
-3529 -3524
3966 3993
1934 1952
-234 -223
-4967 -4947
8500 8510
5272 5276
-6048 -6033
-34 -22
700 705
-7890 -7886
5538 5543
4114 4126
-9201 -9162
-1521 -1519
-5103 -5100
439 441
993 997
-1684 -1680
-8413 -8404
6724 6728
-3242 -3239
2616...

output:

73.175077878

result:

wrong answer 1st numbers differ - expected: '6717.1171457', found: '73.1750779', error = '0.9891062'