QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200752#7344. Those Russian HackersSolitaryDreamWA 0ms20512kbC++202.6kb2023-10-04 19:27:552023-10-04 19:27:55

Judging History

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

  • [2023-10-04 19:27:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:20512kb
  • [2023-10-04 19:27:55]
  • 提交

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=1.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) {
    // FOR(i,0,LenA-1) FOR(j,0,LenB-1) C[i+j]+=A[i]*B[j];
    static comp a[N],b[N];
    int n=1;for(; n<LenA+LenB; n<<=1);
    FOR(i,0,n-1) a[i]=b[i]={0,0};
    FOR(i,0,LenA-1) a[i]={A[i],0};
    FOR(i,0,LenB-1) b[i]={B[i],0};
    DFT(a,n,1);
    DFT(b,n,1);
    FOR(i,0,n-1) b[i]*=a[i];
    // 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 Q[N];
db A[N],B[N];
db sum[N];
int n,K;
db pr;
db qry(int i,int r) {
    db t=0;
    FOR(j,1,n) {
        if(j<=r) {
            if(i==1) {
                t+=Q[n-j]*p[j];
            } else {
                t+=p[j]*(sum[n*3-2]-sum[n-1+j]);
            }
        } else {
            t+=p[j]*max(Q[j-r-1],pr);
        }
    }
    return t;
}
int main() {
    scanf("%d%d",&n,&K);
    FOR(i,1,n) scanf("%lf",&p[i]);
    FOR(i,1,n*2-2) scanf("%lf",&q[i]),Q[i]=Q[i-1]+q[i];
    FOR(i,1,n*2-2) A[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 e=0,r=0;
    db s=0,w=0;
    FOR(j,1,n) s+=p[j]*Q[j-r-1];
    // s=qry(1,0);
    w=s;
    FOR(j,1,n) {
        s+=Q[n-j]*p[j];
        s-=p[j]*Q[j-r-1];
        // s=qry(1,j);
        if(s>=w) {
            w=s;
            r=j;
        }
    }
    pr=w;
    // cerr << r << endl;
    FOR(i,2,K) {
        db w=qry(i,r);
        while(r>0) {
            --r;
            db t=qry(i,r);
            if(t<=w) {
                ++r;
                break;
            }
            w=t;
        }
        pr=w;
    }
    printf("%.9lf\n",pr);
    return 0;
}

詳細信息

Test #1:

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

input:

3 1
0.5 0.25 0.25
0.75 0.25 0.0 0.0

output:

1.125000000

result:

wrong answer 1st numbers differ - expected: '0.6875000', found: '1.1250000', error = '0.4375000'