QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380698 | #7838. 往日之影 | C1942huangjiaxu | 30 | 718ms | 10668kb | C++14 | 1.6kb | 2024-04-07 08:50:51 | 2024-04-07 08:50:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T,P,n,a[4],f[2][105][105][105],C[105][105];
struct Fastmod{
typedef __uint128_t uLL;
typedef unsigned long long ull;
ull P,m;
void init(ull P){
this->P=P,m=(uLL(1)<<64)/P;
}
ull mod(ull a){
ull b=uLL(a)*m>>64;
ull r=a-b*P;
return r>=P?r-P:r;
}
}Z;
int ksm(int x,long long y){
int res=1;
for(;y;y>>=1,x=Z.mod(1ll*x*x))if(y&1)res=Z.mod(1ll*res*x);
return res;
}
inline void Add(int &x,int y){
if((x+=y)>=P)x-=P;
}
void solve(){
scanf("%d",&n);
for(int i=0;i<4;++i)scanf("%d",&a[i]);
for(int i=0;i<=n;++i)for(int j=0;j<=n;++j)for(int k=0;k<=n;++k)f[0][i][j][k]=f[1][i][j][k]=0;
f[0][0][0][0]=1;
for(int o=0,p=0,q=1,t=0;o<4;++o)for(int c=0;c<a[o];++c,++t,p^=1,q^=1){
for(int i=0;i<=t;++i)for(int j=0;j+i<=t;++j)for(int k=0;k+j+i<=t;++k)if(f[p][i][j][k]){
int l=t-i-j-k,v=f[p][i][j][k];//printf("?%d %d %d %d %d\n",t,i,j,k,l);
f[p][i][j][k]=0;
for(int i1=0;i1<=i;++i1)for(int j1=0;j1<=j;++j1)for(int k1=0;k1<=k;++k1)for(int l1=0;l1<=l;++l1){
int w=Z.mod(Z.mod(Z.mod(1ull*C[i][i1]*C[j][j1])*C[k][k1])*C[l][l1]);
int r=(o-i1-j1-k1-l1)&3;
int i0=i-i1+j1,j0=j-j1+k1,k0=k-k1+l1,l0=l-l1+i1;
if(r==0)++i0;
if(r==1)++j0;
if(r==2)++k0;
if(r==3)++l0;
Add(f[q][i0][j0][k0],Z.mod(1ll*v*w));
}
}
}
printf("%d\n",Z.mod(1ll*f[n&1][n][0][0]*ksm(P+1>>1,1ll*n*(n-1)/2)));
}
int main(){
scanf("%d%d",&T,&P);
Z.init(P);
for(int i=0;i<=100;++i)C[i][0]=1;
for(int i=1;i<=100;++i)for(int j=1;j<=i;++j)C[i][j]=Z.mod(C[i-1][j]+C[i-1][j-1]);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 5904kb
input:
1 998244353 3 1 1 0 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5944kb
input:
1 998244353 7 0 2 1 4
output:
998069185
result:
ok single line: '998069185'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6220kb
input:
1 998244353 4 0 1 0 3
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5908kb
input:
1 998244353 2 1 0 1 0
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 7900kb
input:
1 998244353 6 2 1 0 3
output:
997696001
result:
ok single line: '997696001'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5908kb
input:
1 998244353 2 1 0 1 0
output:
0
result:
ok single line: '0'
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 20
Accepted
time: 718ms
memory: 8052kb
input:
1 998244353 40 11 9 9 11
output:
855684614
result:
ok single line: '855684614'
Test #8:
score: 0
Accepted
time: 597ms
memory: 10668kb
input:
1 998244353 39 12 8 7 12
output:
629648158
result:
ok single line: '629648158'
Test #9:
score: 0
Accepted
time: 488ms
memory: 8028kb
input:
1 998244353 38 13 8 9 8
output:
944107686
result:
ok single line: '944107686'
Test #10:
score: 0
Accepted
time: 410ms
memory: 8032kb
input:
1 998244353 37 16 7 7 7
output:
393700837
result:
ok single line: '393700837'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5976kb
input:
4 998244353 10 0 3 2 5 9 2 1 1 5 10 1 2 3 4 9 4 0 3 2
output:
124779131 998235309 124779131 998236023
result:
ok 4 lines
Test #12:
score: 0
Accepted
time: 1ms
memory: 5984kb
input:
4 998244353 10 2 1 4 3 9 1 2 4 2 10 3 2 5 0 9 3 2 2 2
output:
124779131 998239593 124778655 998236261
result:
ok 4 lines
Test #13:
score: 0
Accepted
time: 1ms
memory: 7964kb
input:
4 998244353 10 1 4 1 4 9 2 0 5 2 10 3 5 1 1 9 6 1 1 1
output:
623900891 998239355 374338940 998231025
result:
ok 4 lines
Test #14:
score: 0
Accepted
time: 1ms
memory: 7944kb
input:
8 998244353 4 2 1 0 1 4 0 2 0 2 5 0 1 1 3 4 0 1 0 3 5 1 1 0 3 5 0 3 1 1 4 2 2 0 0 5 1 1 2 1
output:
0 0 995319809 0 997269505 995319809 982646785 996294657
result:
ok 8 lines
Test #15:
score: 0
Accepted
time: 1ms
memory: 6004kb
input:
8 998244353 4 2 1 0 1 4 3 0 1 0 4 0 2 2 0 5 2 0 1 2 5 1 2 0 2 5 0 1 1 3 5 0 1 1 3 4 1 1 1 1
output:
0 0 967049217 997269505 0 995319809 995319809 0
result:
ok 8 lines
Test #16:
score: 0
Accepted
time: 95ms
memory: 8072kb
input:
3 998244353 30 1 10 7 12 8 0 3 0 5 2 0 1 0 1
output:
54137262 998208177 0
result:
ok 3 lines
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #17:
score: 0
Time Limit Exceeded
input:
1 998244353 99 12 22 33 32 15 998244353 7 1 2 2 2 6 1 2 1 2 6 1 1 3 1 7 0 3 1 3 7 1 1 2 3 7 3 1 0 3 6 1 2 1 2 7 1 2 2 2 7 3 3 0 1 6 1 1 3 1 7 5 1 0 1 6 3 0 1 2 6 2 0 0 4 7 2 0 1 4 6 4 1 0 1
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #23:
score: 0
Time Limit Exceeded
input:
999 999999001 2 2 0 0 0 3 3 0 0 0 4 4 0 0 0 5 5 0 0 0 6 6 0 0 0 7 7 0 0 0 8 8 0 0 0 9 9 0 0 0 10 10 0 0 0 11 11 0 0 0 12 12 0 0 0 13 13 0 0 0 14 14 0 0 0 15 15 0 0 0 16 16 0 0 0 17 17 0 0 0 18 18 0 0 0 19 19 0 0 0 20 20 0 0 0 21 21 0 0 0 22 22 0 0 0 23 23 0 0 0 24 24 0 0 0 25 25 0 0 0 26 26 0 0 0 27...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%