QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588523 | #8211. Enumerating Substrings | Tx_Lcy | AC ✓ | 364ms | 67588kb | C++14 | 2.8kb | 2024-09-25 12:43:57 | 2024-09-25 12:43:58 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
int const N=2e6+10,mod=1e9+7;
int n,m,k,ans,pw[N],ivpw[N],dp[N],gt[2005][2005];
inline int qpow(int a,int b){int res=1;while (b){if (b&1) res*=a,res%=mod;a*=a,a%=mod,b>>=1;}return res;}
inline int A(int n,int m){
int g=1;
per(i,n,n-m+1) g*=i,g%=mod;
return g;
}
#define add(x,y) (x=((x+y>=mod)?(x+y-mod):(x+y)))
inline int D(int n,int t){
int nw=0,gr=qpow(pw[t]+mod-1,mod-2);
rep(p,0,t-1){
int Q=0,ed=(n-p)/t*t+p;
Q=(pw[t]*ivpw[p]%mod+mod-ivpw[ed])%mod;
// for (int j=p;j<=ed;j+=t) add(Q,qpow(pw[j],mod-2)%mod);
add(nw,(mod-pw[p])%mod*Q%mod);
}
// rep(i,0,n) add(nw,(mod-pw[i%t])%mod*qpow(pw[i],mod-2)%mod);
return nw*gr%mod;
}
inline void work(int L,int res){
// dp[0]=1;
if (n<=2000 || m<=100){
int nw=0;
rep(i,m,n){
dp[i]=pw[i-m];
if (L) add(dp[i],mod-dp[i-m+L]);
add(nw,dp[i]*pw[n-i]%mod);
}
return add(ans,nw*res%mod),void();
}
// cout<<nw<<" !@#@!#\n";
int nw=0;
if (!L){
rep(i,m,n) add(nw,pw[i-m]*pw[n-i]%mod);
}else{
int t=m-L;
nw=D(n-m,2*t)*pw[n-m]%mod,nw%=mod;
add(nw,pw[n+2*t-m]*(n-m+1)%mod);
int gw=0;
// rep(i,m,n-t){
// int S=n-i-t;
// add(gw,
// (mod-pw[S-S/(2*t)*(2*t)])%mod*pw[i-m]%mod);
// }
gw=D(n-m-t,2*t)*pw[n-m-t]%mod;
// rep(I,0,n-m-t) add(gw,mod-pw[I%(2*t)]*pw[n-I-t-m]%mod);
add(gw,pw[n-m+t]*(n-t-m+1)%mod);
nw+=mod-gw,nw%=mod;
nw*=qpow((pw[2*t]+mod-1)%mod,mod-2),nw%=mod;
}
// cout<<nw<<" Aft!\n";
add(ans,nw*res%mod);
}
inline void solve(){
cin>>n>>m>>k,gt[0][0]=1;
rep(L,1,m) rep(co,1,L){
gt[L][co]=gt[L-1][co-1]*L%mod;
if (L>1) gt[L][co]+=(L*(L-1)/2)%mod*gt[L-2][co-1]%mod,gt[L][co]%=mod;
}
pw[0]=1,ivpw[0]=1;
rep(i,1,N-1) pw[i]=pw[i-1]*k%mod,ivpw[i]=qpow(pw[i],mod-2);
int tot=0,la=1;
rep(co,0,m) tot+=gt[m][co]*la%mod,tot%=mod,la*=k-co,la%=mod,la*=qpow(co+1,mod-2),la%=mod;
rep(L,1,m/2){
int res=0,sd=A(k,L),la=1;
rep(co,0,m-2*L){
res+=sd*la%mod*gt[m-2*L][co]%mod,res%=mod;
la*=k-L-co,la%=mod,la*=qpow(co+1,mod-2),la%=mod;
}
tot+=mod-res,tot%=mod,work(L,res);
}
work(0,tot);
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while (t--) solve();
// cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 208ms
memory: 38872kb
input:
4 2 3
output:
228
result:
ok 1 number(s): "228"
Test #2:
score: 0
Accepted
time: 362ms
memory: 66892kb
input:
999999 1999 12345678
output:
52352722
result:
ok 1 number(s): "52352722"
Test #3:
score: 0
Accepted
time: 216ms
memory: 37664kb
input:
7 4 2
output:
182
result:
ok 1 number(s): "182"
Test #4:
score: 0
Accepted
time: 212ms
memory: 38172kb
input:
4 3 4
output:
480
result:
ok 1 number(s): "480"
Test #5:
score: 0
Accepted
time: 212ms
memory: 38476kb
input:
3 1 1
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 216ms
memory: 38448kb
input:
5 5 1
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 216ms
memory: 38880kb
input:
7 4 3
output:
5784
result:
ok 1 number(s): "5784"
Test #8:
score: 0
Accepted
time: 216ms
memory: 37544kb
input:
5 2 4
output:
3932
result:
ok 1 number(s): "3932"
Test #9:
score: 0
Accepted
time: 207ms
memory: 37232kb
input:
8 2 2
output:
1522
result:
ok 1 number(s): "1522"
Test #10:
score: 0
Accepted
time: 216ms
memory: 37564kb
input:
8 1 2
output:
2048
result:
ok 1 number(s): "2048"
Test #11:
score: 0
Accepted
time: 208ms
memory: 38264kb
input:
7 5 3
output:
2430
result:
ok 1 number(s): "2430"
Test #12:
score: 0
Accepted
time: 212ms
memory: 38664kb
input:
10 4 3
output:
272004
result:
ok 1 number(s): "272004"
Test #13:
score: 0
Accepted
time: 233ms
memory: 46724kb
input:
675978 614 2
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 224ms
memory: 42952kb
input:
244613 38 1
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 293ms
memory: 58444kb
input:
186293 1462 1
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 242ms
memory: 50388kb
input:
24867 886 1
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 261ms
memory: 52644kb
input:
976164 1014 2
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 217ms
memory: 39528kb
input:
179356 2 716844809
output:
577866092
result:
ok 1 number(s): "577866092"
Test #19:
score: 0
Accepted
time: 214ms
memory: 38448kb
input:
621001 130 310625363
output:
892869197
result:
ok 1 number(s): "892869197"
Test #20:
score: 0
Accepted
time: 224ms
memory: 51008kb
input:
678862 850 754662812
output:
582264789
result:
ok 1 number(s): "582264789"
Test #21:
score: 0
Accepted
time: 254ms
memory: 52744kb
input:
650845 978 348443366
output:
825425732
result:
ok 1 number(s): "825425732"
Test #22:
score: 0
Accepted
time: 220ms
memory: 41812kb
input:
669914 402 87448112
output:
318098088
result:
ok 1 number(s): "318098088"
Test #23:
score: 0
Accepted
time: 226ms
memory: 44784kb
input:
998593 530 681228665
output:
408255654
result:
ok 1 number(s): "408255654"
Test #24:
score: 0
Accepted
time: 364ms
memory: 66100kb
input:
369361 1954 125266115
output:
509912384
result:
ok 1 number(s): "509912384"
Test #25:
score: 0
Accepted
time: 280ms
memory: 56408kb
input:
900226 1378 424079373
output:
406320917
result:
ok 1 number(s): "406320917"
Test #26:
score: 0
Accepted
time: 309ms
memory: 58168kb
input:
334887 1506 17859926
output:
503264679
result:
ok 1 number(s): "503264679"
Test #27:
score: 0
Accepted
time: 206ms
memory: 43784kb
input:
936048 544 53978328
output:
548647866
result:
ok 1 number(s): "548647866"
Test #28:
score: 0
Accepted
time: 274ms
memory: 56808kb
input:
152789 1264 792983073
output:
839541707
result:
ok 1 number(s): "839541707"
Test #29:
score: 0
Accepted
time: 297ms
memory: 58768kb
input:
714493 1392 91796331
output:
721071046
result:
ok 1 number(s): "721071046"
Test #30:
score: 0
Accepted
time: 244ms
memory: 47804kb
input:
269571 816 830801077
output:
330064211
result:
ok 1 number(s): "330064211"
Test #31:
score: 0
Accepted
time: 250ms
memory: 50248kb
input:
845120 944 424581630
output:
348960190
result:
ok 1 number(s): "348960190"
Test #32:
score: 0
Accepted
time: 222ms
memory: 42152kb
input:
533990 368 163586376
output:
522092095
result:
ok 1 number(s): "522092095"
Test #33:
score: 0
Accepted
time: 335ms
memory: 62384kb
input:
181707 1792 462399634
output:
373795106
result:
ok 1 number(s): "373795106"
Test #34:
score: 0
Accepted
time: 363ms
memory: 67588kb
input:
417349 1920 761212891
output:
587051329
result:
ok 1 number(s): "587051329"
Test #35:
score: 0
Accepted
time: 280ms
memory: 56012kb
input:
526583 1344 500217637
output:
108767800
result:
ok 1 number(s): "108767800"
Test #36:
score: 0
Accepted
time: 238ms
memory: 48948kb
input:
867054 769 93998191
output:
239123369
result:
ok 1 number(s): "239123369"
Extra Test:
score: 0
Extra Test Passed