QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608306 | #8942. Sugar Sweet 3 | ucup-team902 | AC ✓ | 645ms | 6956kb | C++17 | 3.0kb | 2024-10-03 20:34:47 | 2024-10-03 20:34:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=500;
const int mod=1e9+7;
int C[N+5][N+5],ct[N+5];
int fac[N+5],ifac[N+5];
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int ksm(ll x,int tp,int s=1){
for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
return s;
}
void prep(){
C[0][0]=1; ct[0]=ct[1]=1;
for(int i=1;i<=N;i++){
C[i][0]=C[i][i]=1;
for(int j=1;j<i;j++)
C[i][j]=add(C[i-1][j],C[i-1][j-1]);
}
for(int i=2;i<=N;i++)
for(int j=0;j<i;j++)
ct[i]=(ct[i]+1ll*ct[j]*ct[i-j-1])%mod;
fac[0]=ifac[0]=1;
for(int i=1;i<=N;i++){
fac[i]=1ll*fac[i-1]*i%mod;
ifac[i]=ksm(i,mod-2,ifac[i-1]);
}
}
int a,b,c,x,n;
int f[N+5][N+5];
int val[N+5][N+5];
int sumv[N+5];
void lagerange(int yv[N+5],int ans[N+5]){
static int g[N+5];
g[1]=1;
for(int i=1;i<=n;i++)
for(int j=i+1;j;j--)
g[j]=(g[j-1]+1ll*(mod-i)*g[j])%mod;
for(int i=0;i<=n;i++){
int coe=1;
for(int j=0;j<=n;j++)
if(j!=i) coe=1ll*coe*(i-j)%mod;
coe=ksm((coe+mod)%mod,mod-2,yv[i]);
static int h[N+5];
if(!i){
for(int j=0;j<=n;j++) h[j]=g[j+1];
}
else{
int iv=ksm(i,mod-2);
h[0]=0;
for(int j=1;j<=n;j++)
h[j]=1ll*iv*(mod+h[j-1]-g[j])%mod;
}
for(int j=0;j<=n;j++)
ans[j]=(ans[j]+1ll*coe*h[j])%mod;
}
}
int main(){
prep();
scanf("%d %d %d %d",&a,&b,&c,&x);
if(a+b+c&1){
puts("0");
return 0;
}
n=(a+b+c)/2;
f[0][0]=1;
for(int i=1;i<=n;i++)
for(int k=1;k<=i;k++)
for(int j=1;j-1<=i-k;j++)
f[i][j]=(f[i][j]+1ll*ct[k-1]*f[i-k][j-1])%mod;
for(int i=0;i<=n;i++){
for(int j=1;j<=n;j++)
f[i][j]=1ll*f[i][j]*ifac[j]%mod;
for(int v=0;v<=n;v++)
for(int j=i;j>=0;j--)
val[i][v]=(1ll*val[i][v]*v+f[i][j])%mod;
}
for(int aa=0;aa<=a&&aa<=n;aa++)
for(int bb=0;bb<=b&&aa+bb<=n;bb++){
int cc=n-aa-bb;
int coe=0;
for(int i=0;i<=a-aa&&i<=b;i++){
int j=cc-(a-aa-i);
int k=aa-(b-bb-j);
if(j<0||k<0) continue;
coe=(coe+1ll*C[bb][i]*C[cc][j]%mod*C[aa][k])%mod;
}
// coe=1ll*coe*C[aa+bb][aa]%mod*C[n][cc]%mod;
// printf("%d %d %d %d\n",aa,bb,cc,coe);
for(int v=0;v<=n;v++)
sumv[v]=(sumv[v]+1ll*coe*val[aa][v]%mod*val[bb][v]%mod*val[cc][v])%mod;
}
static int ans[N+5];
lagerange(sumv,ans);
int res=0;
for(int i=1;i<=n;i++){
ans[i]=1ll*ans[i]*fac[i]%mod;
res=add(res,ksm(i,x,ans[i]));
// printf("%d ",ans[i]);
}
// puts("");
printf("%d\n",res);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4988kb
input:
1 2 3 1
output:
110
result:
ok 1 number(s): "110"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4968kb
input:
4 5 7 12
output:
881078346
result:
ok 1 number(s): "881078346"
Test #3:
score: 0
Accepted
time: 2ms
memory: 6476kb
input:
1 1 7 8
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 2ms
memory: 6560kb
input:
13 26 88 45
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 225ms
memory: 6892kb
input:
100 300 400 1515897
output:
279831696
result:
ok 1 number(s): "279831696"
Test #6:
score: 0
Accepted
time: 191ms
memory: 6360kb
input:
120 310 298 1155114
output:
903227392
result:
ok 1 number(s): "903227392"
Test #7:
score: 0
Accepted
time: 2ms
memory: 6764kb
input:
1 1 2 1
output:
18
result:
ok 1 number(s): "18"
Test #8:
score: 0
Accepted
time: 0ms
memory: 4896kb
input:
5 5 10 1919810
output:
696652039
result:
ok 1 number(s): "696652039"
Test #9:
score: 0
Accepted
time: 2ms
memory: 4720kb
input:
1 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 169ms
memory: 6432kb
input:
1 1 798 15154848
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 173ms
memory: 6696kb
input:
1 399 400 1616897
output:
987648925
result:
ok 1 number(s): "987648925"
Test #12:
score: 0
Accepted
time: 332ms
memory: 6416kb
input:
400 398 2 45458123
output:
830387421
result:
ok 1 number(s): "830387421"
Test #13:
score: 0
Accepted
time: 6ms
memory: 6956kb
input:
89 75 18 66278
output:
940243796
result:
ok 1 number(s): "940243796"
Test #14:
score: 0
Accepted
time: 633ms
memory: 6888kb
input:
333 333 334 1
output:
60970749
result:
ok 1 number(s): "60970749"
Test #15:
score: 0
Accepted
time: 581ms
memory: 6948kb
input:
334 333 333 1000000000
output:
159064905
result:
ok 1 number(s): "159064905"
Test #16:
score: 0
Accepted
time: 347ms
memory: 6956kb
input:
1 499 500 1515987
output:
880517266
result:
ok 1 number(s): "880517266"
Test #17:
score: 0
Accepted
time: 645ms
memory: 6812kb
input:
500 498 2 1514789
output:
93909141
result:
ok 1 number(s): "93909141"
Test #18:
score: 0
Accepted
time: 510ms
memory: 6908kb
input:
250 250 500 19198877
output:
172243832
result:
ok 1 number(s): "172243832"
Test #19:
score: 0
Accepted
time: 601ms
memory: 6832kb
input:
300 300 400 75787941
output:
778545661
result:
ok 1 number(s): "778545661"
Test #20:
score: 0
Accepted
time: 2ms
memory: 4992kb
input:
7 16 11 1568
output:
725510153
result:
ok 1 number(s): "725510153"
Extra Test:
score: 0
Extra Test Passed