QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593014#5433. Absolute Differencepengpeng_fudanWA 1ms3956kbC++141.9kb2024-09-27 11:08:062024-09-27 11:08:07

Judging History

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

  • [2024-09-27 11:08:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3956kb
  • [2024-09-27 11:08:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll =long long;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<pair<long double,long double>> a(n+1);
    vector<pair<long double,long double>> b(m+1);
    for(int i=1;i<=n;i++)   cin>>a[i].first>>a[i].second;
    for(int i=1;i<=m;i++)   cin>>b[i].first>>b[i].second;
    sort(a.begin()+1,a.end());
    sort(b.begin()+1,b.end());
    vector<long double> qza(n+1),qzb(m+1);
    ll suma=0,sumb=0;
    for(int i=1;i<=n;i++)   suma+=a[i].second-a[i].first;
    for(int i=1;i<=n;i++){
        if(suma==0) qza[i]=1;
        else qza[i]=(a[i].second-a[i].first);
    }

    for(int i=1;i<=n;i++)   sumb+=b[i].second-b[i].first;
    for(int i=1;i<=n;i++){
        if(sumb==0) qzb[i]=1;
        else qzb[i]=(b[i].second-b[i].first);
    }
    if(suma==0)  suma=n;
    if(sumb==0)  sumb=m;
    long double ans=0;
    auto ope=[&](int t)->void {
        long double sb=0,sqzb=0;
        int lo=1;
        for(int i=1;i<(int)a.size();i++){
            while(lo!=(int)b.size()&&b[lo].second<=a[i].first)   {
                sb+=(b[lo].second+b[lo].first)/2*qzb[lo];
                sqzb+=qzb[lo];
                lo++;
            }
            ans+=-sb*qza[i]+sqzb*qza[i]*(a[i].first+a[i].second)/2;
            int ro=lo;
            while(ro!=(int)b.size()&&(t?b[ro].second<a[i].second:b[ro].second<=a[i].second)){
                auto [x1,x2]=a[i];
                auto [y1,y2]=b[i];
                ans+=((x1+x2)/2-(y1+y2)/2)*qza[i]*qzb[lo]-(x1-y2)*(x1-y2)*(x1-y2)/3;
                // cerr<<b[ro].second<<' '<<a[i].second<<' '<<ans<<'\n';
                ro++;
            }
        }
    };
    ope(1);
    swap(a,b);swap(qza,qzb);
    ope(0);
    cout<<setprecision(12)<<(ans/suma)/sumb<<'\n';

}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int _ = 1;
    while (_--) solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3732kb

input:

1 1
0 1
0 1

output:

0.333333333333

result:

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

Test #2:

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

input:

1 1
0 1
1 1

output:

0.5

result:

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

Test #3:

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

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.667

result:

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

Test #4:

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

input:

1 1
-1000000000 0
0 1000000000

output:

1000000000

result:

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

Test #5:

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

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000

result:

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

Test #6:

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

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.5

result:

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

Test #7:

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

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999

result:

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

Test #8:

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

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000

result:

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

Test #9:

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

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:

6719.60272291

result:

wrong answer 1st numbers differ - expected: '6717.1171457', found: '6719.6027229', error = '0.0003700'