QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88185 | #4903. 细菌 | zhouhuanyi | 100 ✓ | 879ms | 12736kb | C++23 | 4.4kb | 2023-03-15 14:36:00 | 2023-03-15 14:36:01 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 120000
#define M 20000000
#define K 480000
#define g 3
#define mod 998244353
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
int fast_pow(int a,int b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
int d,n,m,k,a,b,c,s1,s2,res,ans,rev[K+1],fac[N+1],invfac[N+1],A[K+1],B[K+1],C[K+1],dp[N+1],DP[N+1],delta[N+1];
int F(int x)
{
return (x>0)?x>>1:-((-x+1)>>1);
}
int Cs(int x,int y)
{
if (x<y) return 0;
return 1ll*fac[x]*invfac[y]%mod*invfac[x-y]%mod;
}
int G(int x,int y)
{
if (y<0) y=-y;
if ((x+y)&1) return 0;
return Cs(x,(x+y)>>1);
}
void calc(int x,int r,int ds)
{
delta[0]=(1<=r&&r<=x);
for (int i=1;i<=d;++i)
{
delta[i]=2ll*delta[i-1]%mod;
Adder(delta[i],G(i-1,-r)),Adder(delta[i],G(i-1,r-(x+1)));
Adder2(delta[i],-G(i-1,1-r)),Adder2(delta[i],-G(i-1,r-x));
}
for (int i=0;i<=d;++i)
{
if (ds==1) Adder(dp[i],delta[i]);
else Adder2(dp[i],-delta[i]);
}
return;
}
void solve(int x,int r)
{
int ds=1,sr=r,op=0;
calc(x,r,1);
while (1)
{
if (!op) r=-r;
else r=((x+1)<<1)-r;
if (r<1-d||r>x+d) break;
op^=1,ds=-ds,calc(x,r,ds);
}
ds=op=1,r=sr;
while (1)
{
if (!op) r=-r;
else r=((x+1)<<1)-r;
if (r<1-d||r>x+d) break;
op^=1,ds=-ds,calc(x,r,ds);
}
return;
}
void NTT(int limit,int *s,int type)
{
int d,s1,s2;
for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(limit>>1):0);
for (int i=0;i<limit;++i)
if (rev[i]>i)
swap(s[i],s[rev[i]]);
for (int i=2,w;i<=limit;i<<=1)
{
if (type==1) w=fast_pow(g,(mod-1)/i);
else w=fast_pow(g,(mod-1)/i*(i-1));
for (int j=0;j+i-1<=limit;j+=i)
for (int k=j,wn=1;k<j+(i>>1);++k,wn=1ll*wn*w%mod)
s1=s[k],s2=1ll*s[k+(i>>1)]*wn%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
}
if (type==-1)
{
d=fast_pow(limit,mod-2);
for (int i=0;i<limit;++i) s[i]=1ll*s[i]*d%mod;
}
return;
}
int main()
{
int limit=1;
fac[0]=1;
for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
invfac[N]=fast_pow(fac[N],mod-2);
for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
d=read(),n=read(),m=read(),k=read(),a=read(),b=read(),c=read();
if (1ll*n*n<=10*d)
{
for (int i=1;i<=n;++i) dp[i]=1;
A[0]=1;
for (int i=1;i<=d;++i)
{
for (int j=1;j<=n;++j) DP[j]=0;
for (int j=1;j<=n;++j)
{
if (j-1>=1) Adder(DP[j-1],dp[j]);
if (j+1<=n) Adder(DP[j+1],dp[j]);
}
for (int j=1;j<=n;++j) dp[j]=DP[j];
Adder(A[i],dp[a]);
}
}
else
{
for (int i=0;i<=d;++i) dp[i]=0;
solve(n,a);
for (int i=0;i<=d;++i) A[i]=dp[i];
}
if (1ll*m*m<=10*d)
{
for (int i=1;i<=m;++i) dp[i]=1;
B[0]=1;
for (int i=1;i<=d;++i)
{
for (int j=1;j<=m;++j) DP[j]=0;
for (int j=1;j<=m;++j)
{
if (j-1>=1) Adder(DP[j-1],dp[j]);
if (j+1<=m) Adder(DP[j+1],dp[j]);
}
for (int j=1;j<=m;++j) dp[j]=DP[j];
Adder(B[i],dp[b]);
}
}
else
{
for (int i=0;i<=d;++i) dp[i]=0;
solve(m,b);
for (int i=0;i<=d;++i) B[i]=dp[i];
}
if (1ll*k*k<=3*d)
{
for (int i=1;i<=k;++i) dp[i]=1;
C[0]=1;
for (int i=1;i<=d;++i)
{
for (int j=1;j<=k;++j) DP[j]=0;
for (int j=1;j<=k;++j)
{
if (j-1>=1) Adder(DP[j-1],dp[j]);
if (j+1<=k) Adder(DP[j+1],dp[j]);
}
for (int j=1;j<=k;++j) dp[j]=DP[j];
Adder(C[i],dp[c]);
}
}
else
{
for (int i=0;i<=d;++i) dp[i]=0;
solve(k,c);
for (int i=0;i<=d;++i) C[i]=dp[i];
}
for (int i=0;i<=d;++i) A[i]=1ll*A[i]*invfac[i]%mod,B[i]=1ll*B[i]*invfac[i]%mod;
while (limit<=(d<<1)) limit<<=1;
NTT(limit,A,1),NTT(limit,B,1);
for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
NTT(limit,A,-1);
for (int i=0;i<=d;++i) Adder(ans,1ll*A[i]*C[d-i]%mod*invfac[d-i]%mod*fac[d]%mod);
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 2ms
memory: 11612kb
input:
50 41 46 42 8 20 21
output:
791406134
result:
ok 1 number(s): "791406134"
Test #2:
score: 0
Accepted
time: 3ms
memory: 11584kb
input:
50 49 44 48 49 15 25
output:
544847893
result:
ok 1 number(s): "544847893"
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #3:
score: 10
Accepted
time: 3ms
memory: 11904kb
input:
5000 4994 4990 4990 976 2257 2505
output:
836390717
result:
ok 1 number(s): "836390717"
Test #4:
score: 0
Accepted
time: 4ms
memory: 11864kb
input:
5000 4994 4997 4994 4399 1826 1332
output:
65414465
result:
ok 1 number(s): "65414465"
Subtask #3:
score: 15
Accepted
Test #5:
score: 15
Accepted
time: 96ms
memory: 10864kb
input:
120000 300 1 1 141 1 1
output:
637174
result:
ok 1 number(s): "637174"
Test #6:
score: 0
Accepted
time: 206ms
memory: 11780kb
input:
120000 994 1 1 15 1 1
output:
218803691
result:
ok 1 number(s): "218803691"
Test #7:
score: 0
Accepted
time: 43ms
memory: 12592kb
input:
120000 119999 1 1 19896 1 1
output:
68846585
result:
ok 1 number(s): "68846585"
Subtask #4:
score: 10
Accepted
Test #8:
score: 10
Accepted
time: 53ms
memory: 12556kb
input:
119000 119991 119991 1 23819 52139 1
output:
944500934
result:
ok 1 number(s): "944500934"
Subtask #5:
score: 15
Accepted
Dependency #4:
100%
Accepted
Test #9:
score: 15
Accepted
time: 104ms
memory: 12504kb
input:
120000 13997 13996 1 42 9266 1
output:
775637357
result:
ok 1 number(s): "775637357"
Test #10:
score: 0
Accepted
time: 100ms
memory: 12512kb
input:
120000 13997 13997 1 9768 6131 1
output:
151873213
result:
ok 1 number(s): "151873213"
Subtask #6:
score: 35
Accepted
Dependency #3:
100%
Accepted
Dependency #5:
100%
Accepted
Test #11:
score: 35
Accepted
time: 149ms
memory: 11776kb
input:
120000 294 296 1 142 273 1
output:
889786082
result:
ok 1 number(s): "889786082"
Test #12:
score: 0
Accepted
time: 173ms
memory: 11968kb
input:
120000 395 390 1 370 185 1
output:
884557050
result:
ok 1 number(s): "884557050"
Test #13:
score: 0
Accepted
time: 206ms
memory: 11672kb
input:
120000 491 495 1 430 25 1
output:
272929924
result:
ok 1 number(s): "272929924"
Test #14:
score: 0
Accepted
time: 246ms
memory: 11720kb
input:
120000 590 593 1 418 459 1
output:
446962505
result:
ok 1 number(s): "446962505"
Test #15:
score: 0
Accepted
time: 287ms
memory: 11624kb
input:
120000 697 690 1 166 450 1
output:
216092107
result:
ok 1 number(s): "216092107"
Test #16:
score: 0
Accepted
time: 314ms
memory: 10896kb
input:
120000 793 799 1 416 61 1
output:
661260042
result:
ok 1 number(s): "661260042"
Test #17:
score: 0
Accepted
time: 413ms
memory: 11784kb
input:
120000 1000 1000 1 613 547 1
output:
429669083
result:
ok 1 number(s): "429669083"
Test #18:
score: 0
Accepted
time: 450ms
memory: 12036kb
input:
120000 1993 1995 1 493 565 1
output:
609392900
result:
ok 1 number(s): "609392900"
Test #19:
score: 0
Accepted
time: 205ms
memory: 12488kb
input:
120000 4995 4998 1 3166 3765 1
output:
394497547
result:
ok 1 number(s): "394497547"
Test #20:
score: 0
Accepted
time: 121ms
memory: 12736kb
input:
120000 9994 9991 1 6099 691 1
output:
795651799
result:
ok 1 number(s): "795651799"
Test #21:
score: 0
Accepted
time: 56ms
memory: 12392kb
input:
120000 49990 49990 1 41933 2862 1
output:
360787513
result:
ok 1 number(s): "360787513"
Test #22:
score: 0
Accepted
time: 47ms
memory: 11924kb
input:
120000 119996 119994 1 58014 49559 1
output:
682979057
result:
ok 1 number(s): "682979057"
Subtask #7:
score: 10
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Test #23:
score: 10
Accepted
time: 201ms
memory: 11816kb
input:
120000 296 300 297 89 130 280
output:
702788425
result:
ok 1 number(s): "702788425"
Test #24:
score: 0
Accepted
time: 249ms
memory: 11932kb
input:
120000 392 397 391 222 280 10
output:
322470184
result:
ok 1 number(s): "322470184"
Test #25:
score: 0
Accepted
time: 308ms
memory: 11688kb
input:
120000 499 498 500 263 315 367
output:
449848666
result:
ok 1 number(s): "449848666"
Test #26:
score: 0
Accepted
time: 367ms
memory: 12292kb
input:
120000 598 591 594 497 474 400
output:
35486519
result:
ok 1 number(s): "35486519"
Test #27:
score: 0
Accepted
time: 879ms
memory: 12344kb
input:
120000 694 692 695 625 173 477
output:
785203749
result:
ok 1 number(s): "785203749"
Test #28:
score: 0
Accepted
time: 844ms
memory: 12084kb
input:
120000 794 796 800 395 465 507
output:
897269426
result:
ok 1 number(s): "897269426"
Test #29:
score: 0
Accepted
time: 800ms
memory: 12624kb
input:
120000 993 998 991 196 712 911
output:
464727191
result:
ok 1 number(s): "464727191"
Test #30:
score: 0
Accepted
time: 673ms
memory: 12380kb
input:
120000 1991 2000 1994 1937 1362 1494
output:
473701811
result:
ok 1 number(s): "473701811"
Test #31:
score: 0
Accepted
time: 286ms
memory: 12416kb
input:
120000 4994 4990 4990 646 1214 2276
output:
763540821
result:
ok 1 number(s): "763540821"
Test #32:
score: 0
Accepted
time: 168ms
memory: 12284kb
input:
120000 9994 9992 9991 6588 9538 2632
output:
804858722
result:
ok 1 number(s): "804858722"
Test #33:
score: 0
Accepted
time: 66ms
memory: 12336kb
input:
120000 49997 49997 49993 46278 44140 26931
output:
139550295
result:
ok 1 number(s): "139550295"
Test #34:
score: 0
Accepted
time: 57ms
memory: 12460kb
input:
120000 119997 120000 120000 24867 116477 35338
output:
946147605
result:
ok 1 number(s): "946147605"