QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#810029 | #9782. NonZero PrefSuf Sums | Afterlife# | AC ✓ | 25ms | 12484kb | C++20 | 3.1kb | 2024-12-11 19:13:59 | 2024-12-11 19:14:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n , m , mod ;
int fpow(int a,int b) {
int ans = 1;
while(b) {
if(b & 1) ans = 1LL * ans * a %mod;
a = 1LL * a * a % mod ; b >>= 1;
}
return ans;
}
int t[105] , rt[105];
int C(int a,int b) {
return 1LL * t[a] * rt[b] % mod * rt[a - b] % mod;
}
const int D = 1e4 ;
// int f[20005] , g[20005];
int calc() {
vector<int> f(20005) , g(20005) ;
f[D] = 1;
for(int i = 1;i <= n;i++) {
for(int j = -i*m ; j <= i *m;j++) {
f[D + j] = (f[D + j] + f[D + j - 1]) % mod;
}
for(auto &x : g) x = 0;
for(int j = -i * m ; j <= i * m ; j++) {
g[D + j] = (f[D + min(i*m , j + m)] - f[max(0 , D + j - m - 1)] + mod) % mod;
}
for(int j = -i*m ; j <= i*m;j++) f[D + j] = g[D + j] ;
}
return f[D];
}
int f[105][105][105] , g[105][105][105];
int calcm(int mx) { //// max <= mx
// vector<vector<int> > f(n + 1 , vector<int>(n + 1)) ;
// vector<vector<int> > g(n + 1 , vector<int>(n + 1)) ;
f[mx][0][0] = 1;
for(int i = 0;i <= n;i++) g[mx][0][i] = 1;
for(int i = 1;i <= n;i++) {
for(int j = 0 ; j <= n ; j++) {
if(j <= mx) f[mx][i][j] = g[mx][i - 1][j];
else f[mx][i][j] = (g[mx][i - 1][j] - g[mx][i - 1][j - mx - 1] + mod) % mod;
f[mx][i][j] = (f[mx][i][j] - f[mx][i - 1][j] + mod) % mod;
}
g[mx][i][0] = f[mx][i][0];
for(int j = 1;j <= n;j++) {
g[mx][i][j] = (f[mx][i][j] + g[mx][i][j - 1]) % mod;
}
}
int ans = 0;
for(int neg = 1 ; neg < n ; neg++) {
// printf("neg %d : %d : %d\n" , neg , g[n - neg][neg - 1] - g[n-neg][min(neg-1 , max(0,lm-1))] , (g[n - neg][neg - 1] - g[n-neg][min(neg-1 , max(0,lm-1))] ) * C(n , neg)) ;
// printf("B %d : %d\n" , min(neg - 1 , max(0 , lm - 1)) , lm) ;
for(int zero = 0 ; zero + neg < n ; zero++) {
// int lm = (n - zero - 1) / 2;
int lm = neg - mx - 1;
int tk = (g[mx][n - neg - zero][neg - 1] - g[mx][n-neg - zero][min(neg-1 , max(0,lm-1))] + mod) % mod;
int pre = (g[mx - 1][n - neg - zero][neg - 1] - g[mx - 1][n-neg - zero][min(neg-1 , max(0,lm-1))] + mod) % mod;
tk = (tk - pre + mod) % mod;
ans = (ans + 1LL * tk * C(n , neg) % mod * C(n-neg , zero)) % mod;
}
}
ans = ans*2 % mod;
return ans;
}
int main() {
cin >> n >> m >> mod ;
t[0] = rt[0] = 1;
for(int i = 1;i <= n;i++) {
t[i] = 1LL * t[i - 1] * i % mod;
rt[i] = fpow(t[i] , mod - 2) ;
}
int ans = fpow(m*2 + 1 , n) ;
ans = (ans - calc() + mod) % mod; /// case1
ans = (ans - 1LL * (m*2) * n + mod) % mod; // case2
vector<int> sol(m + 1);
for(int mx = 1 ; mx <= m ; mx++) {
sol[mx] = calcm(mx) ;
// printf("%d %d\n",mx,sol[mx]) ;
}
for(int i = 1;i <= m;i++) {
// int s = (sol[i] - sol[i - 1] + mod) % mod;
int s=sol[i];
ans = (ans - 1LL * s * (m/i) % mod + mod) % mod;
}
cout << ans << '\n' ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6004kb
input:
2 1 998244353
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 6ms
memory: 10908kb
input:
69 42 696969697
output:
378553557
result:
ok single line: '378553557'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5936kb
input:
2 1 998244353
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 9992kb
input:
69 42 696969697
output:
378553557
result:
ok single line: '378553557'
Test #5:
score: 0
Accepted
time: 8ms
memory: 10900kb
input:
61 75 677323601
output:
34613998
result:
ok single line: '34613998'
Test #6:
score: 0
Accepted
time: 0ms
memory: 6064kb
input:
13 14 670577333
output:
41465431
result:
ok single line: '41465431'
Test #7:
score: 0
Accepted
time: 0ms
memory: 5864kb
input:
14 6 987686347
output:
37536510
result:
ok single line: '37536510'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
15 12 196428923
output:
29322522
result:
ok single line: '29322522'
Test #9:
score: 0
Accepted
time: 2ms
memory: 6000kb
input:
68 7 786815587
output:
149281835
result:
ok single line: '149281835'
Test #10:
score: 0
Accepted
time: 1ms
memory: 6008kb
input:
3 2 503002109
output:
82
result:
ok single line: '82'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
13 5 756093197
output:
415698676
result:
ok single line: '415698676'
Test #12:
score: 0
Accepted
time: 1ms
memory: 6020kb
input:
2 3 646574611
output:
30
result:
ok single line: '30'
Test #13:
score: 0
Accepted
time: 4ms
memory: 12388kb
input:
39 68 120037189
output:
43217507
result:
ok single line: '43217507'
Test #14:
score: 0
Accepted
time: 1ms
memory: 5692kb
input:
13 4 423132517
output:
360231790
result:
ok single line: '360231790'
Test #15:
score: 0
Accepted
time: 0ms
memory: 7824kb
input:
14 3 309713387
output:
94215386
result:
ok single line: '94215386'
Test #16:
score: 0
Accepted
time: 0ms
memory: 12104kb
input:
24 77 886983941
output:
211636479
result:
ok single line: '211636479'
Test #17:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
3 3 504388063
output:
270
result:
ok single line: '270'
Test #18:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
3 1 936205423
output:
8
result:
ok single line: '8'
Test #19:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
3 3 295983139
output:
270
result:
ok single line: '270'
Test #20:
score: 0
Accepted
time: 1ms
memory: 7940kb
input:
10 15 446169107
output:
149884328
result:
ok single line: '149884328'
Test #21:
score: 0
Accepted
time: 0ms
memory: 10076kb
input:
37 18 833753929
output:
592917251
result:
ok single line: '592917251'
Test #22:
score: 0
Accepted
time: 1ms
memory: 5988kb
input:
11 3 998773403
output:
860630017
result:
ok single line: '860630017'
Test #23:
score: 0
Accepted
time: 2ms
memory: 10332kb
input:
14 85 688036639
output:
347188409
result:
ok single line: '347188409'
Test #24:
score: 0
Accepted
time: 1ms
memory: 5792kb
input:
3 3 844621907
output:
270
result:
ok single line: '270'
Test #25:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
3 4 204335891
output:
620
result:
ok single line: '620'
Test #26:
score: 0
Accepted
time: 1ms
memory: 7844kb
input:
7 8 113007667
output:
58946097
result:
ok single line: '58946097'
Test #27:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
4 1 637268377
output:
22
result:
ok single line: '22'
Test #28:
score: 0
Accepted
time: 1ms
memory: 6092kb
input:
11 14 391637237
output:
303270280
result:
ok single line: '303270280'
Test #29:
score: 0
Accepted
time: 1ms
memory: 5756kb
input:
3 2 208286231
output:
82
result:
ok single line: '82'
Test #30:
score: 0
Accepted
time: 1ms
memory: 6024kb
input:
2 11 662696483
output:
462
result:
ok single line: '462'
Test #31:
score: 0
Accepted
time: 0ms
memory: 10080kb
input:
19 55 974135299
output:
887460557
result:
ok single line: '887460557'
Test #32:
score: 0
Accepted
time: 1ms
memory: 5708kb
input:
6 8 417027509
output:
23351024
result:
ok single line: '23351024'
Test #33:
score: 0
Accepted
time: 1ms
memory: 7904kb
input:
8 13 624006587
output:
353008442
result:
ok single line: '353008442'
Test #34:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
10 10 740294671
output:
79436611
result:
ok single line: '79436611'
Test #35:
score: 0
Accepted
time: 1ms
memory: 7836kb
input:
11 10 394088657
output:
161476458
result:
ok single line: '161476458'
Test #36:
score: 0
Accepted
time: 1ms
memory: 7824kb
input:
9 27 562853573
output:
135252259
result:
ok single line: '135252259'
Test #37:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
8 3 829129009
output:
5349034
result:
ok single line: '5349034'
Test #38:
score: 0
Accepted
time: 0ms
memory: 10156kb
input:
51 49 924010279
output:
815049368
result:
ok single line: '815049368'
Test #39:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
12 2 308466749
output:
223013998
result:
ok single line: '223013998'
Test #40:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
7 4 567557693
output:
4502296
result:
ok single line: '4502296'
Test #41:
score: 0
Accepted
time: 4ms
memory: 10920kb
input:
36 93 943780729
output:
13599465
result:
ok single line: '13599465'
Test #42:
score: 0
Accepted
time: 0ms
memory: 5720kb
input:
2 1 828681127
output:
2
result:
ok single line: '2'
Test #43:
score: 0
Accepted
time: 0ms
memory: 5824kb
input:
3 3 534160729
output:
270
result:
ok single line: '270'
Test #44:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
7 12 920925433
output:
453086694
result:
ok single line: '453086694'
Test #45:
score: 0
Accepted
time: 1ms
memory: 7804kb
input:
3 2 440546987
output:
82
result:
ok single line: '82'
Test #46:
score: 0
Accepted
time: 3ms
memory: 7880kb
input:
90 9 291269963
output:
72560304
result:
ok single line: '72560304'
Test #47:
score: 0
Accepted
time: 1ms
memory: 6188kb
input:
38 10 867575113
output:
165530481
result:
ok single line: '165530481'
Test #48:
score: 0
Accepted
time: 3ms
memory: 7932kb
input:
48 37 152663531
output:
135425620
result:
ok single line: '135425620'
Test #49:
score: 0
Accepted
time: 1ms
memory: 7860kb
input:
15 15 991731803
output:
102703562
result:
ok single line: '102703562'
Test #50:
score: 0
Accepted
time: 25ms
memory: 12484kb
input:
100 100 696969697
output:
313377809
result:
ok single line: '313377809'
Extra Test:
score: 0
Extra Test Passed