QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200574#7343. Bicycle RaceSolitaryDream#WA 0ms18424kbC++202.7kb2023-10-04 17:37:482023-10-04 17:37:48

Judging History

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

  • [2023-10-04 17:37:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:18424kb
  • [2023-10-04 17:37:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
typedef double db;
typedef long long ll;
const int N=1e6+50;
typedef complex<db> comp;
const db pi=acos(-1);
void DFT(comp *a,int n,int f) {
    static comp ww[N],iw[N];
    static int rev[N],pn=0;
    if(pn!=n) {
        FOR(i,0,n-1) ww[i]=comp(cos(pi*2/n*i),sin(pi*2/n*i));
        FOR(i,0,n-1) iw[i]=conj(ww[i]);
        FOR(i,0,n-1) rev[i]=(rev[i>>1]>>1)|((i&1)*(n>>1));
        pn=n;
    }
    comp *w=f>0?ww:iw;
    FOR(i,0,n-1) if(rev[i]<i) swap(a[rev[i]],a[i]);
    for(int l=2; l<=n; l<<=1) {
        for(comp *p=a; p!=a+n; p+=l) {
            for(int i=0,m=l>>1; i<m; ++i) {
                comp t=p[i+m];
                p[i+m]=p[i]+t*w[n/l*(i+m)];
                p[i]=p[i]+t*w[n/l*i];
            }
        }
    }
    if(f<0) FOR(i,0,n-1) a[i]/=n;
}
void Poly_Mul(const db *A,int LenA,const db *B,int LenB,db *C) {
    static comp a[N],b[N];
    int n=1;for(; n<LenA+LenB; n<<=1);
    FOR(i,0,n-1) a[i]={0,0};
    FOR(i,0,LenA-1) a[i]={(db)A[i],0};
    FOR(i,0,LenB-1) b[i]={a[i].real(),(db)B[i]};
    DFT(a,n,1);
    FOR(i,0,n-1) b[i]=(a[i]*a[i]-conj(a[i?n-i:0]*a[i?n-i:0]))*comp(0,-0.25);
    DFT(b,n,-1);
    FOR(i,0,n-1) C[i]=b[i].real();
}
db p[N],q[N];
db A[N],B[N];
db sum[N];
int main() {
    int n,K;
    scanf("%d%d",&n,&K);
    FOR(i,1,n) scanf("%lf",&p[i]);
    FOR(i,1,n*2-2) scanf("%lf",&q[i]);
    FOR(i,1,n*2-2) B[i]=q[n*2-1-i];
    Poly_Mul(p,n+1,A,n*2-1,B);
    FOR(i,1,n+n*2-2) sum[i]=sum[i-1]+B[i];
    int r=n;
    db v=0;
    FOR(i,1,K) {
        db w;
        {
            db t=0;
            FOR(j,1,n) {
                if(j<=r) {
                    if(K==1) {
                        FOR(k,1,n*2-2) {
                            if(j+k<=n) t+=q[k]*p[j];
                        }
                    } else {
                        t+=p[j]*(sum[n*3-2]-sum[n*3-j-2]);
                    }
                } else {
                    t+=v*p[j];
                }
            }
            w=t;
        }
        while(r>0) {
            --r;
            db t=0;
            FOR(j,1,n) {
                if(j<=r) {
                    if(K==1) {
                        FOR(k,1,n*2-2) {
                            if(j+k<=n) t+=q[k]*p[j];
                        }
                    } else {
                        t+=p[j]*(sum[n*3-2]-sum[n*3-j-2]);
                    }
                } else {
                    t+=v*p[j];
                }
            }
            if(t<w) {
                ++r;
                break;
            }
            w=t;
        }
        v=w;
    }
    cout << v << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 18424kb

input:

6 9
1 2 3
2 3 1
3 4 2
4 5 1
3 5 7
2 5 2
1 5 3
4 6 2
5 6 1

output:

2.84852e-05

result:

wrong output format Expected integer, but "2.84852e-05" found