QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75578 | #4908. 完全表示 | 4182_543_731 | 100 ✓ | 608ms | 47312kb | C++ | 4.0kb | 2023-02-05 20:46:23 | 2023-02-05 20:46:27 |
Judging History
answer
#include<cstdio>
using namespace std;
#define N 105900
#define M 1059
#define K 42
#define mod 164511353
int n,k,m,tp,ri=41,as,rp;
int v1[M][K],sv[M][K],c[M][M],t2[K],rv[M],s[M][M],f[M];
int pw(int a,int p){int as=1;while(p){if(p&1)as=1ll*as*a%mod;a=1ll*a*a%mod;p>>=1;}return as;}
int vf[N][K],vg[N][K],pr[K];
void solve(int p,int q)
{
for(int i=0;i<ri;i++)for(int j=0;j<=m;j++)v1[j][i]=0;
for(int i=0;i<=ri;i++)vf[0][i]=vg[n+m+1][i]=i==1;
for(int i=1;i<=n+m;i++)
{
int vl=mod-pw(p,n-i+mod-1);
for(int j=0;j<ri;j++)vf[i][j]=0;
for(int j=0;j<ri;j++)vf[i][j*p%ri]=(vf[i][j*p%ri]+vf[i-1][j])%mod;
for(int j=0;j<ri;j++)vf[i][j]=(vf[i][j]+1ll*vl*vf[i-1][j])%mod;
if(i%n==0)
{
for(int j=0;j<ri;j++)vf[i][j]=0;
vf[i][p%ri]=1;vf[i][1]+=vl;
}
}
for(int i=n+m;i>=1;i--)
{
int vl=mod-pw(p,n-i+mod-1);
for(int j=0;j<ri;j++)vg[i][j]=0;
for(int j=0;j<ri;j++)vg[i][j*p%ri]=(vg[i][j*p%ri]+vg[i+1][j])%mod;
for(int j=0;j<ri;j++)vg[i][j]=(vg[i][j]+1ll*vl*vg[i+1][j])%mod;
if(i%n==0)for(int j=0;j<=ri;j++)vg[i][j]=j==1;
}
int s1=1;for(int i=1;i<=n*(q-1);i++)s1=s1*p%ri;
int s2=pw(p,n*q);
for(int i=0;i<=m;i++)
{
int l=i+1,r=i+n,s3=pw(s2,i);
for(int p=0;p<ri;p++)for(int q=0;q<=ri;q++)
{
int nt=p*q*s1%ri;
v1[i][nt]=(v1[i][nt]+1ll*vf[r][p]*vg[l][q]%mod*s3)%mod;
}
}
}
int r1[K][K],r2[K][K];
int is[N*10],si[K];
void dfs(int nw,int si,int pr)
{
if(nw==k){is[si]=pr==(1<<k)-1;return;}
dfs(nw+1,si,pr);
si|=1<<nw;
int p1=pr;
for(int i=0;i<k;i++)p1|=1<<r2[i][nw];
while(p1>pr)
{
int u=0;
for(int i=0;i<k;i++)if(((p1^pr)>>i)&1)u=i;
pr+=1<<u;
for(int j=0;j<=k;j++)if((p1>>j)&1)p1|=1<<r1[u][j];
}
dfs(nw+1,si,pr);
}
void solve_1()
{
for(int i=0;i<=m;i++)sv[i][1]=1;
for(int i=2;i<=k;i++)if(k%i==0)
{
int su=0;while(k%i==0)su++,k/=i;
solve(i,su);
for(int p=0;p<=m;p++)
{
for(int j=0;j<ri;j++)t2[j]=0;
for(int a=0;a<ri;a++)for(int b=0;b<ri;b++)
{
int nt=1ll*a*b%ri;
t2[nt]=(t2[nt]+1ll*v1[p][a]*sv[p][b])%mod;
}
for(int j=0;j<ri;j++)sv[p][j]=t2[j];
}
}
}
void solve_2()
{
for(int i=0;i<k;i++)for(int j=0;j<k;j++)scanf("%d",&r1[i][j]);
for(int i=0;i<k;i++)for(int j=0;j<k;j++)scanf("%d",&r2[i][j]);
dfs(0,0,0);
for(int i=1;i<1<<k;i<<=1)
for(int j=0;j<1<<k;j+=i*2)
for(int k=0;k<i;k++)
is[j+k]-=is[j+k+i];
for(int i=0;i<1<<k;i++)
{
int ci=0;
for(int j=0;j<k;j++)if((i>>j)&1)ci++;
si[ci]+=is[i];
}
for(int i=0;i<ri;i++)vf[0][i]=vg[n+m+1][i]=i==1;
for(int i=1;i<=n+m;i++)
{
for(int j=0;j<ri;j++)vf[i][j]=0;
for(int l=1;l<=k;l++)if(si[l])
{
int vl=1ll*pw(l,i-n+mod-1)*(si[l]+mod)%mod;
for(int j=0;j<ri;j++)vf[i][j*l%ri]=(vf[i][j*l%ri]+1ll*vl*vf[i-1][j])%mod;
}
if(i%n==0)
{
for(int j=0;j<ri;j++)vf[i][j]=0;
for(int l=1;l<=k;l++)if(si[l])vf[i][l]=1ll*pw(l,i-n+mod-1)*(si[l]+mod)%mod;
}
}
for(int i=n+m;i>=1;i--)
{
for(int j=0;j<ri;j++)vg[i][j]=0;
for(int l=1;l<=k;l++)if(si[l])
{
int vl=1ll*pw(l,i-n+mod-1)*(si[l]+mod)%mod;
for(int j=0;j<ri;j++)vg[i][j*l%ri]=(vg[i][j*l%ri]+1ll*vl*vg[i+1][j])%mod;
}
if(i%n==0)for(int j=0;j<ri;j++)vg[i][j]=j==1;
}
int s1=pw(k,1ll*n*(n-1)/2%(mod-1));
for(int i=0;i<=m;i++)
{
int l=i+1,r=i+n;
for(int p=0;p<=ri;p++)for(int q=0;q<=ri;q++)
{
int nt=p*q%ri;
sv[i][nt]=(sv[i][nt]+1ll*vf[r][p]*vg[l][q]%mod*s1)%mod;
}
}
}
int main()
{
scanf("%d%d%d%d",&n,&k,&m,&tp);
for(int i=0;i<=m;i++)c[i][0]=c[i][i]=1;
for(int i=2;i<=m;i++)for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
s[0][0]=1;
for(int i=1;i<=m;i++)for(int j=1;j<=i;j++)s[i][j]=1ll*j*(s[i-1][j-1]+s[i-1][j])%mod;
if(tp==1)solve_1();
else solve_2();
for(int j=0;j<=m;j++)for(int i=0;i<ri;i++)rv[j]=(rv[j]+1ll*sv[j][i]*pw(2,i))%mod;
f[0]=1;
for(int i=0;i<=m;i++)
{
for(int j=0;j<=m;j++)as=(as+1ll*s[m][i]*f[j]%mod*rv[j])%mod;
for(int j=m;j>=0;j--)f[j+1]=(f[j+1]+f[j])%mod,f[j]=1ll*f[j]*(mod-i)%mod;
int tp=pw(2*(i+1),mod-2);for(int j=m;j>=0;j--)f[j]=1ll*f[j]*tp%mod;
}
printf("%d\n",as);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 17ms
memory: 7444kb
input:
2 3 665 1
output:
51745605
result:
ok "51745605"
Test #2:
score: 0
Accepted
time: 19ms
memory: 7348kb
input:
2 4 641 1
output:
54153482
result:
ok "54153482"
Test #3:
score: 0
Accepted
time: 35ms
memory: 7488kb
input:
1 6 656 1
output:
119347748
result:
ok "119347748"
Test #4:
score: 0
Accepted
time: 6ms
memory: 3104kb
input:
1 8 170 1
output:
126971959
result:
ok "126971959"
Test #5:
score: 0
Accepted
time: 23ms
memory: 8828kb
input:
1 9 816 1
output:
14287284
result:
ok "14287284"
Test #6:
score: 0
Accepted
time: 10ms
memory: 3688kb
input:
1 12 233 1
output:
37178137
result:
ok "37178137"
Test #7:
score: 0
Accepted
time: 4ms
memory: 3772kb
input:
1 16 244 1
output:
91022688
result:
ok "91022688"
Test #8:
score: 0
Accepted
time: 13ms
memory: 3548kb
input:
1 18 218 1
output:
93037058
result:
ok "93037058"
Test #9:
score: 0
Accepted
time: 20ms
memory: 7360kb
input:
1 19 645 1
output:
53944276
result:
ok "53944276"
Test #10:
score: 0
Accepted
time: 20ms
memory: 4588kb
input:
1 20 333 1
output:
81197702
result:
ok "81197702"
Test #11:
score: 0
Accepted
time: 30ms
memory: 9476kb
input:
1 2 893 1
output:
17672119
result:
ok "17672119"
Test #12:
score: 0
Accepted
time: 34ms
memory: 9548kb
input:
1 19 887 1
output:
58567516
result:
ok "58567516"
Test #13:
score: 0
Accepted
time: 18ms
memory: 6096kb
input:
2 3 504 1
output:
60763909
result:
ok "60763909"
Subtask #2:
score: 15
Accepted
Test #14:
score: 15
Accepted
time: 0ms
memory: 1512kb
input:
19 90203 0 1
output:
142145213
result:
ok "142145213"
Test #15:
score: 0
Accepted
time: 1ms
memory: 1636kb
input:
18 9697 0 1
output:
153592927
result:
ok "153592927"
Test #16:
score: 0
Accepted
time: 1ms
memory: 1640kb
input:
20 41 0 1
output:
112957727
result:
ok "112957727"
Test #17:
score: 0
Accepted
time: 1ms
memory: 1740kb
input:
20 99991 0 1
output:
151341559
result:
ok "151341559"
Subtask #3:
score: 5
Accepted
Dependency #2:
100%
Accepted
Test #18:
score: 5
Accepted
time: 2ms
memory: 1928kb
input:
999 9749 0 1
output:
77370298
result:
ok "77370298"
Test #19:
score: 0
Accepted
time: 2ms
memory: 1960kb
input:
997 55103 0 1
output:
92054017
result:
ok "92054017"
Test #20:
score: 0
Accepted
time: 2ms
memory: 1952kb
input:
1000 41 0 1
output:
6438830
result:
ok "6438830"
Test #21:
score: 0
Accepted
time: 0ms
memory: 1956kb
input:
1000 99991 0 1
output:
31676606
result:
ok "31676606"
Subtask #4:
score: 5
Accepted
Dependency #3:
100%
Accepted
Test #22:
score: 5
Accepted
time: 83ms
memory: 34316kb
input:
99996 20089 0 1
output:
163612442
result:
ok "163612442"
Test #23:
score: 0
Accepted
time: 86ms
memory: 34308kb
input:
99996 17707 0 1
output:
109099283
result:
ok "109099283"
Test #24:
score: 0
Accepted
time: 86ms
memory: 34440kb
input:
100000 41 0 1
output:
131161322
result:
ok "131161322"
Test #25:
score: 0
Accepted
time: 74ms
memory: 34380kb
input:
100000 99991 0 1
output:
84487741
result:
ok "84487741"
Subtask #5:
score: 15
Accepted
Test #26:
score: 15
Accepted
time: 2ms
memory: 1944kb
input:
998 24 0 1
output:
75129854
result:
ok "75129854"
Test #27:
score: 0
Accepted
time: 0ms
memory: 1928kb
input:
998 35 0 1
output:
120341894
result:
ok "120341894"
Test #28:
score: 0
Accepted
time: 3ms
memory: 1944kb
input:
1000 30 0 1
output:
152799538
result:
ok "152799538"
Test #29:
score: 0
Accepted
time: 2ms
memory: 1936kb
input:
1000 82 0 1
output:
117109540
result:
ok "117109540"
Test #30:
score: 0
Accepted
time: 0ms
memory: 1960kb
input:
1000 100 0 1
output:
89805014
result:
ok "89805014"
Subtask #6:
score: 5
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #31:
score: 5
Accepted
time: 213ms
memory: 34312kb
input:
99998 20726 0 1
output:
63876769
result:
ok "63876769"
Test #32:
score: 0
Accepted
time: 305ms
memory: 34412kb
input:
99998 10270 0 1
output:
47691333
result:
ok "47691333"
Test #33:
score: 0
Accepted
time: 436ms
memory: 34408kb
input:
100000 30030 0 1
output:
80481158
result:
ok "80481158"
Test #34:
score: 0
Accepted
time: 446ms
memory: 34440kb
input:
100000 94710 0 1
output:
61977663
result:
ok "61977663"
Test #35:
score: 0
Accepted
time: 151ms
memory: 34436kb
input:
100000 100000 0 1
output:
163629325
result:
ok "163629325"
Subtask #7:
score: 15
Accepted
Dependency #6:
100%
Accepted
Test #36:
score: 15
Accepted
time: 9ms
memory: 2520kb
input:
96 26444 100 1
output:
28274469
result:
ok "28274469"
Test #37:
score: 0
Accepted
time: 4ms
memory: 2528kb
input:
96 1381 98 1
output:
108507497
result:
ok "108507497"
Test #38:
score: 0
Accepted
time: 16ms
memory: 2516kb
input:
100 30030 100 1
output:
96954743
result:
ok "96954743"
Test #39:
score: 0
Accepted
time: 16ms
memory: 2532kb
input:
100 94710 100 1
output:
4473750
result:
ok "4473750"
Test #40:
score: 0
Accepted
time: 6ms
memory: 2552kb
input:
100 100000 100 1
output:
119621887
result:
ok "119621887"
Subtask #8:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #7:
100%
Accepted
Test #41:
score: 15
Accepted
time: 319ms
memory: 43256kb
input:
99996 23632 996 1
output:
25805700
result:
ok "25805700"
Test #42:
score: 0
Accepted
time: 319ms
memory: 43328kb
input:
99998 15516 997 1
output:
55584997
result:
ok "55584997"
Test #43:
score: 0
Accepted
time: 605ms
memory: 43248kb
input:
100000 30030 1000 1
output:
131562265
result:
ok "131562265"
Test #44:
score: 0
Accepted
time: 608ms
memory: 43248kb
input:
100000 94710 1000 1
output:
149443247
result:
ok "149443247"
Test #45:
score: 0
Accepted
time: 214ms
memory: 43244kb
input:
100000 100000 1000 1
output:
111554062
result:
ok "111554062"
Subtask #9:
score: 15
Accepted
Test #46:
score: 15
Accepted
time: 143ms
memory: 43184kb
input:
99997 3 997 2 0 1 2 1 2 0 2 0 1 0 0 0 0 1 2 0 2 1
output:
16632035
result:
ok "16632035"
Test #47:
score: 0
Accepted
time: 151ms
memory: 43212kb
input:
99997 4 999 2 0 1 2 3 1 0 3 2 2 3 0 1 3 2 1 0 0 0 0 0 0 1 2 3 0 2 3 1 0 3 1 2
output:
137547387
result:
ok "137547387"
Test #48:
score: 0
Accepted
time: 268ms
memory: 43224kb
input:
100000 6 1000 2 0 1 2 3 4 5 1 2 3 4 5 0 2 3 4 5 0 1 3 4 5 0 1 2 4 5 0 1 2 3 5 0 1 2 3 4 0 0 0 0 0 0 0 1 2 3 4 5 0 2 4 0 2 4 0 3 0 3 0 3 0 4 2 0 4 2 0 5 4 3 2 1
output:
16561140
result:
ok "16561140"
Test #49:
score: 0
Accepted
time: 205ms
memory: 43180kb
input:
99999 8 1000 2 0 1 2 3 4 5 6 7 1 4 3 5 7 6 2 0 2 3 0 1 5 4 7 6 3 5 1 4 6 7 0 2 4 7 5 6 0 2 3 1 5 6 4 7 2 0 1 3 6 2 7 0 3 1 4 5 7 0 6 2 1 3 5 4 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 2 2 0 0 2 0 2 0 3 0 3 4 4 6 6 0 4 0 4 0 0 4 4 0 5 2 4 0 2 4 5 0 6 0 6 4 4 3 3 0 7 2 6 4 5 3 1
output:
163171319
result:
ok "163171319"
Test #50:
score: 0
Accepted
time: 153ms
memory: 43120kb
input:
99997 8 1000 2 0 1 2 3 4 5 6 7 1 2 3 0 5 6 7 4 2 3 0 1 6 7 4 5 3 0 1 2 7 4 5 6 4 5 6 7 0 1 2 3 5 6 7 4 1 2 3 0 6 7 4 5 2 3 0 1 7 4 5 6 3 0 1 2 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 2 0 2 0 2 0 2 0 3 2 1 4 7 6 5 0 4 0 4 0 4 0 4 0 5 2 7 4 1 6 3 0 6 0 6 0 6 0 6 0 7 2 5 4 3 6 1
output:
300232
result:
ok "300232"
Test #51:
score: 0
Accepted
time: 147ms
memory: 43196kb
input:
99997 8 997 2 0 1 2 3 4 5 6 7 1 2 3 0 5 6 7 4 2 3 0 1 6 7 4 5 3 0 1 2 7 4 5 6 4 5 6 7 0 1 2 3 5 6 7 4 1 2 3 0 6 7 4 5 2 3 0 1 7 4 5 6 3 0 1 2 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 2 0 2 0 2 0 2 0 3 2 1 4 7 6 5 0 4 0 4 2 6 2 6 0 5 2 7 6 3 4 1 0 6 0 6 2 4 2 4 0 7 2 5 6 1 4 3
output:
24928366
result:
ok "24928366"
Test #52:
score: 0
Accepted
time: 193ms
memory: 43212kb
input:
100000 8 999 2 0 1 2 3 4 5 6 7 1 0 7 6 5 4 3 2 2 7 0 5 6 3 4 1 3 6 5 0 7 2 1 4 4 5 6 7 0 1 2 3 5 4 3 2 1 0 7 6 6 3 4 1 2 7 0 5 7 2 1 4 3 6 5 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 2 0 0 2 0 2 2 0 3 2 3 2 5 0 5 0 4 0 0 4 0 4 4 0 5 2 3 0 5 2 3 0 6 0 0 6 0 6 6 0 7 2 3 6 5 4 1
output:
142695202
result:
ok "142695202"
Test #53:
score: 0
Accepted
time: 211ms
memory: 43372kb
input:
99997 16 999 2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 7 6 5 4 3 2 13 12 15 14 9 8 11 10 2 7 0 5 6 3 4 1 10 11 8 9 14 15 12 13 3 6 5 0 7 2 1 4 11 10 9 8 15 14 13 12 4 5 6 7 0 1 2 3 12 13 14 15 8 9 10 11 5 4 3 2 1 0 7 6 9 8 11 10 13 12 15 14 6 3 4 1 2 7 0 5 14 15 12 13 10 11 8 9 7 2 1 4 3 6 5 0 15 ...
output:
40840083
result:
ok "40840083"
Test #54:
score: 0
Accepted
time: 399ms
memory: 44232kb
input:
99996 18 1000 2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 4 3 5 2 0 9 8 11 10 7 6 15 14 17 16 13 12 2 3 0 1 5 4 7 6 9 8 11 10 13 12 15 14 17 16 3 5 1 4 0 2 8 9 10 11 6 7 14 15 16 17 12 13 4 2 5 0 3 1 10 11 6 7 8 9 16 17 12 13 14 15 5 0 4 2 1 3 11 10 7 6 9 8 17 16 13 12 15 14 6 9 7 8 10 11 12 13 ...
output:
155029514
result:
ok "155029514"
Test #55:
score: 0
Accepted
time: 154ms
memory: 45232kb
input:
100000 19 996 2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 18 14 11 5 15 9 10 0 2 3 4 13 17 12 16 6 8 7 2 14 4 8 1 18 3 13 9 11 17 0 15 16 5 7 10 6 12 3 11 8 16 9 2 13 5 10 17 15 6 1 18 0 14 12 7 4 4 5 1 9 14 12 8 16 11 0 6 2 7 10 18 13 17 3 15 5 15 18 2 12 13 0 6 4 1 9 14 10 3 7 17 8 11 16 6 ...
output:
18522199
result:
ok "18522199"
Test #56:
score: 0
Accepted
time: 310ms
memory: 47312kb
input:
99999 20 1000 2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 3 7 8 9 6 2 4 5 0 16 17 18 19 15 11 12 13 14 10 2 7 3 4 5 0 1 8 9 6 11 12 13 14 10 16 17 18 19 15 3 8 4 5 0 2 7 9 6 1 12 13 14 10 11 17 18 19 15 16 4 9 5 0 2 3 8 6 1 7 13 14 10 11 12 18 19 15 16 17 5 6 0 2 3 4 9 1 7 8 14 10 11 12 13...
output:
26568180
result:
ok "26568180"