QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200627 | #7344. Those Russian Hackers | PlentyOfPenalty | WA | 14ms | 118940kb | C++20 | 2.5kb | 2023-10-04 18:02:41 | 2023-10-04 18:02:42 |
Judging History
answer
#include "bits/stdc++.h"
const double PI=acos(-1.0);
const int MAXN = 2097211;
struct comp
{
double x,y;
comp(double _x=0,double _y=0){x=_x,y=_y;}
comp operator+ (comp you){return comp(x+you.x,y+you.y);}
comp operator- (comp you){return comp(x-you.x,y-you.y);}
comp operator* (comp you){return comp(x*you.x-y*you.y,x*you.y+y*you.x);}
};
comp tf[MAXN],tg[MAXN],RT[MAXN];
int init(int n)
{
int len=1;
while(len<=n+2)len<<=1;
for(int i=1;i<len;i<<=1)
{
comp R(cos(PI/i),sin(PI/i));
RT[i]=1;
for(int j=1;j<i;++j)
RT[i+j]=RT[i+j-1]*R;
}
return len;
}
int rev[MAXN];
void DFT(comp* a,int len)
{
for(int i=0;i<len;++i)
rev[i]=(rev[i>>1]>>1)|(i&1?len>>1:0);
for(int i=0;i<len;++i)
if(rev[i]>i)std::swap(a[i],a[rev[i]]);
for(int cur=1;cur<len;cur<<=1)
for(int j=0;j<len;j+=cur<<1)
for(int k=0;k<cur;++k)
{
comp x=a[j+k],y=RT[cur+k]*a[j+cur+k];
a[j+k]=x+y,a[j+cur+k]=x-y;
}
}
void IDFT(comp* a,int len)
{
std::reverse(a+1,a+len);
DFT(a,len);
for(int i=0;i<len;++i)a[i].x/=len;
}
int len;
void Mul(double* f,double* g,double* res)
{
for(int i=0;i<len;++i)tf[i]=comp(f[i],0);
for(int i=0;i<len;++i)tg[i]=comp(g[i],0);
DFT(tf,len),DFT(tg,len);
for(int i=0;i<len;++i)tf[i]=tf[i]*tg[i];
IDFT(tf,len);
for(int i=0;i<len;++i)res[i]=tf[i].x;
}
double p[MAXN],q[MAXN],r[MAXN],sq[MAXN];
double tp[MAXN],tq[MAXN];
double win[MAXN],f[MAXN];
double dp[MAXN],prod[MAXN];
int main()
{
#ifdef memset0
freopen("B.in","r",stdin);
#endif
int n,k;
scanf("%d%d",&n,&k);
len=init(6*n+10);
for(int i=0;i<n;++i)scanf("%lf",&p[i]);
for(int i=1;i<=2*n-2;++i)scanf("%lf",&q[i]),sq[i]=sq[i-1]+q[i];
for(int i=2*n-1;i>=0;--i)r[i]=r[i+1]+p[i];
for(int d=0;d<=2*n;++d)
tq[2*n-d]=r[d];
for(int d=0;d<=n;++d)
tq[2*n+d]=1;
Mul(q,tq,win);
// for(int t=0;t<n;++t)
// {
// for(int k=1;k<=2*n-2;++k)
// if(k<t)win[t]+=q[k];
// else win[t]+=q[k]*r[k-t];
// //printf("win[%d]=%.10lf\n",t,win[t]);
// }
f[0]=0;
for(int i=1;i<k;++i)
{
for(int j=0;j<n;++j)
f[i]+=p[j]*std::max(win[2*n+n-j-1],f[i-1]);
f[i]=std::max(f[i],win[2*n]);
//printf("F[%d]=%.10lf\n",i,f[i]);
}
for(int i=0;i<n;++i)
{
tp[i]=0;
for(int k=1;i+k-1<=n;++k)
tp[i]+=q[k]*r[i+k]/r[i];
}
for(int i=n-1;i>=0;--i)
{
if(r[i]<1e-7)
{
dp[i]=sq[n-i];
continue;
}
dp[i]=p[i]/r[i]*sq[n-i-1]+(r[i+1]/r[i])*dp[i+1];
dp[i]=std::max(dp[i],tp[i]);
}
printf("%.10lf\n",std::max(f[k-1],dp[0]));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 117992kb
input:
3 1 0.5 0.25 0.25 0.75 0.25 0.0 0.0
output:
0.6875000000
result:
ok found '0.6875000', expected '0.6875000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 7ms
memory: 118476kb
input:
3 2 0.3 0.4 0.3 0.0 0.0 0.0 1.0
output:
0.0900000000
result:
ok found '0.0900000', expected '0.0900000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 117800kb
input:
3 1 0.5 0.2 0.3 1.0 0.0 0.0 0.0
output:
0.8000000000
result:
ok found '0.8000000', expected '0.8000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 3ms
memory: 118940kb
input:
2 1 1.0 0.0 0.7 0.3
output:
0.7000000000
result:
ok found '0.7000000', expected '0.7000000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 4ms
memory: 116676kb
input:
2 2 0.0 1.0 0.6 0.4
output:
0.6000000000
result:
ok found '0.6000000', expected '0.6000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 7ms
memory: 117384kb
input:
3 1 0.1 0.1 0.8 1.0 0.0 0.0 0.0
output:
0.9000000000
result:
ok found '0.9000000', expected '0.9000000', error '0.0000000'
Test #7:
score: 0
Accepted
time: 3ms
memory: 117360kb
input:
2 1 0.196570 0.803430 0.417660 0.582340
output:
0.3355605738
result:
ok found '0.3355606', expected '0.3355606', error '0.0000000'
Test #8:
score: 0
Accepted
time: 7ms
memory: 118388kb
input:
2 1 0.392496 0.607504 1.000000 0.000000
output:
0.6075040000
result:
ok found '0.6075040', expected '0.6075040', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 116564kb
input:
10 1 0.012643 0.123624 0.053820 0.040365 0.028873 0.020157 0.055711 0.484945 0.098421 0.081441 0.085328 0.047990 0.714931 0.138813 0.012938 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
output:
0.9010275479
result:
ok found '0.9010275', expected '0.9010275', error '0.0000000'
Test #10:
score: 0
Accepted
time: 3ms
memory: 117764kb
input:
10 1 0.006649 0.073200 0.000565 0.045068 0.112668 0.035625 0.046072 0.103194 0.005569 0.571390 0.195573 0.074055 0.047683 0.369439 0.161507 0.054811 0.055588 0.037380 0.003964 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
output:
0.8538333808
result:
ok found '0.8538334', expected '0.8538334', error '0.0000000'
Test #11:
score: 0
Accepted
time: 3ms
memory: 117968kb
input:
10 1 0.145228 0.019318 0.105821 0.185187 0.088991 0.042625 0.024569 0.088478 0.047174 0.252609 0.018498 0.107130 0.001316 0.120833 0.069263 0.099338 0.005632 0.009075 0.036279 0.023135 0.008573 0.029578 0.025695 0.067194 0.023536 0.116172 0.157449 0.081304
output:
0.3063300066
result:
ok found '0.3063300', expected '0.3063300', error '0.0000000'
Test #12:
score: -100
Wrong Answer
time: 4ms
memory: 117544kb
input:
10 10 0.044299 0.160436 0.044139 0.088241 0.291281 0.136777 0.020766 0.124310 0.013255 0.076496 0.081824 0.025457 0.068874 0.265701 0.558144 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
output:
0.9999806868
result:
wrong answer 1st numbers differ - expected: '0.9999839', found: '0.9999807', error = '0.0000032'