QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323259 | #8211. Enumerating Substrings | arnold518 | AC ✓ | 20ms | 23684kb | C++17 | 1.9kb | 2024-02-09 02:12:37 | 2024-02-09 02:12:38 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
const int MAXM = 2000;
const int MOD = 1e9+7;
struct mint
{
int x;
mint() : x(0) {}
mint(int _x) : x(_x) {}
mint operator + (int ot) const { return x+ot>=MOD ? x+ot-MOD : x+ot; }
mint operator - () const { return x ? MOD-x : 0; }
mint operator - (int ot) const { return x<ot ? x+MOD-ot : x-ot; }
mint operator * (int ot) const { return 1ll*x*ot%MOD; }
mint operator += (int ot) { return *this=*this+ot; }
mint operator -= (int ot) { return *this=*this-ot; }
mint operator *= (int ot) { return *this=*this*ot; }
operator int() { return x; }
};
mint mpow(mint a, int x)
{
mint ret=1;
while(x)
{
if(x&1) ret*=a;
a=a*a; x>>=1;
}
return ret;
}
mint inv(mint x) { return mpow(x, MOD-2); }
int N, M, K;
mint dp[MAXM+10][MAXM+10];
mint powK[MAXN+10], ans;
mint f(int M, int K)
{
if(K<0) return 0;
mint ncr=1;
mint ret=0;
for(int i=0, j=1; i<=M; i++)
{
if((M+i)%2) continue;
for(; j<=(M+i)/2; j++)
{
if(K-j+1>=0) ncr*=(K-j+1);
}
ret+=dp[M][i]*ncr;
}
return ret;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
scanf("%d%d%d", &N, &M, &K);
powK[0]=1;
for(int i=1; i<=N; i++) powK[i]=powK[i-1]*K;
dp[0][0]=1;
for(int i=0; i<=M; i++)
{
for(int j=0; j<=i; j++)
{
if(j) dp[i+1][j-1]+=dp[i][j]*j;
dp[i+1][j+1]+=dp[i][j];
}
}
mint val=f(M, K);
mint ncr=1;
for(int i=1; i<=M/2; i++)
{
if(K-i+1>=0) ncr*=mint(K-i+1);
mint g=ncr*f(M-i-i, K-i);
int y=M-i;
mint val2=0;
for(int t=0; t*y<=N-M; t++)
{
if(t%2==0) val2+=powK[N-M-t*y]*(N-M-t*y+1);
else val2-=powK[N-M-t*y]*(N-M-t*y+1);
}
ans+=val2*g;
val-=g;
}
ans+=mint(N-M+1)*powK[N-M]*val;
printf("%d\n", (int)ans);
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 23680kb
input:
4 2 3
output:
228
result:
ok 1 number(s): "228"
Test #2:
score: 0
Accepted
time: 20ms
memory: 23636kb
input:
999999 1999 12345678
output:
52352722
result:
ok 1 number(s): "52352722"
Test #3:
score: 0
Accepted
time: 0ms
memory: 23640kb
input:
7 4 2
output:
182
result:
ok 1 number(s): "182"
Test #4:
score: 0
Accepted
time: 0ms
memory: 23556kb
input:
4 3 4
output:
480
result:
ok 1 number(s): "480"
Test #5:
score: 0
Accepted
time: 4ms
memory: 23640kb
input:
3 1 1
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 4ms
memory: 23576kb
input:
5 5 1
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 23500kb
input:
7 4 3
output:
5784
result:
ok 1 number(s): "5784"
Test #8:
score: 0
Accepted
time: 0ms
memory: 23628kb
input:
5 2 4
output:
3932
result:
ok 1 number(s): "3932"
Test #9:
score: 0
Accepted
time: 0ms
memory: 23500kb
input:
8 2 2
output:
1522
result:
ok 1 number(s): "1522"
Test #10:
score: 0
Accepted
time: 0ms
memory: 23504kb
input:
8 1 2
output:
2048
result:
ok 1 number(s): "2048"
Test #11:
score: 0
Accepted
time: 0ms
memory: 23500kb
input:
7 5 3
output:
2430
result:
ok 1 number(s): "2430"
Test #12:
score: 0
Accepted
time: 0ms
memory: 23684kb
input:
10 4 3
output:
272004
result:
ok 1 number(s): "272004"
Test #13:
score: 0
Accepted
time: 4ms
memory: 23680kb
input:
675978 614 2
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 0ms
memory: 23560kb
input:
244613 38 1
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 3ms
memory: 23500kb
input:
186293 1462 1
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 2ms
memory: 23684kb
input:
24867 886 1
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 8ms
memory: 23592kb
input:
976164 1014 2
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 0ms
memory: 23500kb
input:
179356 2 716844809
output:
577866092
result:
ok 1 number(s): "577866092"
Test #19:
score: 0
Accepted
time: 4ms
memory: 23644kb
input:
621001 130 310625363
output:
892869197
result:
ok 1 number(s): "892869197"
Test #20:
score: 0
Accepted
time: 7ms
memory: 23676kb
input:
678862 850 754662812
output:
582264789
result:
ok 1 number(s): "582264789"
Test #21:
score: 0
Accepted
time: 7ms
memory: 23552kb
input:
650845 978 348443366
output:
825425732
result:
ok 1 number(s): "825425732"
Test #22:
score: 0
Accepted
time: 4ms
memory: 23640kb
input:
669914 402 87448112
output:
318098088
result:
ok 1 number(s): "318098088"
Test #23:
score: 0
Accepted
time: 8ms
memory: 23636kb
input:
998593 530 681228665
output:
408255654
result:
ok 1 number(s): "408255654"
Test #24:
score: 0
Accepted
time: 11ms
memory: 23676kb
input:
369361 1954 125266115
output:
509912384
result:
ok 1 number(s): "509912384"
Test #25:
score: 0
Accepted
time: 14ms
memory: 23644kb
input:
900226 1378 424079373
output:
406320917
result:
ok 1 number(s): "406320917"
Test #26:
score: 0
Accepted
time: 11ms
memory: 23640kb
input:
334887 1506 17859926
output:
503264679
result:
ok 1 number(s): "503264679"
Test #27:
score: 0
Accepted
time: 11ms
memory: 23500kb
input:
936048 544 53978328
output:
548647866
result:
ok 1 number(s): "548647866"
Test #28:
score: 0
Accepted
time: 3ms
memory: 23616kb
input:
152789 1264 792983073
output:
839541707
result:
ok 1 number(s): "839541707"
Test #29:
score: 0
Accepted
time: 9ms
memory: 23560kb
input:
714493 1392 91796331
output:
721071046
result:
ok 1 number(s): "721071046"
Test #30:
score: 0
Accepted
time: 3ms
memory: 23644kb
input:
269571 816 830801077
output:
330064211
result:
ok 1 number(s): "330064211"
Test #31:
score: 0
Accepted
time: 8ms
memory: 23556kb
input:
845120 944 424581630
output:
348960190
result:
ok 1 number(s): "348960190"
Test #32:
score: 0
Accepted
time: 3ms
memory: 23624kb
input:
533990 368 163586376
output:
522092095
result:
ok 1 number(s): "522092095"
Test #33:
score: 0
Accepted
time: 7ms
memory: 23540kb
input:
181707 1792 462399634
output:
373795106
result:
ok 1 number(s): "373795106"
Test #34:
score: 0
Accepted
time: 9ms
memory: 23496kb
input:
417349 1920 761212891
output:
587051329
result:
ok 1 number(s): "587051329"
Test #35:
score: 0
Accepted
time: 8ms
memory: 23620kb
input:
526583 1344 500217637
output:
108767800
result:
ok 1 number(s): "108767800"
Test #36:
score: 0
Accepted
time: 7ms
memory: 23640kb
input:
867054 769 93998191
output:
239123369
result:
ok 1 number(s): "239123369"
Extra Test:
score: 0
Extra Test Passed