QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786195#9782. NonZero PrefSuf Sumsucup-team2172AC ✓1311ms57924kbC++232.7kb2024-11-26 20:39:432024-11-26 20:39:47

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 20:39:47]
  • 评测
  • 测评结果:AC
  • 用时:1311ms
  • 内存:57924kb
  • [2024-11-26 20:39:43]
  • 提交

answer

#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int ch = 0, f = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
} 

const int N = 105;
int dp[N][2*N*N], f[N][N][N*N], inv[N], js[N], n, m, mod;

inline int Pow(int a, int b){
    int ans = 1;
    for(; b; b >>= 1, a = 1ll * a * a % mod)
        if(b & 1) ans = 1ll * ans * a % mod;
    return ans;
}
int main(){
    read(n), read(m), read(mod);

    int all = 1; inv[0] = 1;
    for(int i = 1; i <= n; i++){
        all = 1ll * all * i % mod;
        js[i] = all;
        inv[i] = Pow(all, mod - 2);
    }

    int res1 = 0;
    for(int i = 0; i <= m; i++) f[0][i][0] = 1;
    for(int j = 1; j <= m; j++)
        for(int i = 1; i <= n; i++)
            for(int k = 0; k <= n; k++)
                for(int p = 0; p <= i && k - p * j >= 0; p++){
                    (f[i][j][k] += 1ll * f[i-p][j-1][k-p*j] * inv[p] % mod) %= mod;
                }
    
    // cout << f[1][2][2] << " " << f[1][1][1] << endl;

    for(int a = 1; a <= m; a++)
        for(int i = 1; i < n; i++){
            int sum = 0, tmp = 0;
            for(int j = 1; j + i <= n; j++)
                for(int k = 1; k < i; k++)
                    (tmp += 1ll * f[j][m/a][k] * inv[n-i-j] % mod) %= mod;
                          
            for(int b = 1; b <= m / a; b++)
                for(int j = 1; j + i <= n; j++)
                    for(int k = 0; k + b + 2 <= i && k < i; k++)
                        (sum += 1ll * (f[j][b][k] - f[j][b-1][k] + mod) * inv[n-i-j] % mod) %= mod;
                    
            sum = 1ll * sum * js[n] % mod * inv[i] % mod;
            tmp = 1ll * tmp * js[n] % mod * inv[i] % mod;
            // cout << a << " " << i << " " << sum << " " << tmp << endl;
            res1 = (res1 + tmp) % mod;
            res1 = (res1 - sum + mod) % mod;
        }
    
    res1 = 2ll * res1 % mod;
    
    // cout << res1 << endl;

    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
        for(int s = 0; s <= 2 * i * m; s++)
            for(int j = 0; j <= 2 * m && j <= s; j++)
                (dp[i][s] += dp[i-1][s-j]) %= mod;
    
    int res2 = dp[n][n*m];


    //case 2: only positive or only negative
    int res3 = 2ll * m * n % mod;
    //case 3: all zero
    int res = (res1 + res2 + res3) % mod;
    int ans = 1;
    // cout << res << endl;

    for(int i = 1; i <= n; i++) ans = 1ll * (2 * m + 1) * ans % mod;
    cout << ((ans - res) % mod + mod) % mod << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5684kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 125ms
memory: 21204kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5556kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 127ms
memory: 21144kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #5:

score: 0
Accepted
time: 245ms
memory: 28564kb

input:

61 75 677323601

output:

34613998

result:

ok single line: '34613998'

Test #6:

score: 0
Accepted
time: 1ms
memory: 6332kb

input:

13 14 670577333

output:

41465431

result:

ok single line: '41465431'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5948kb

input:

14 6 987686347

output:

37536510

result:

ok single line: '37536510'

Test #8:

score: 0
Accepted
time: 1ms
memory: 6312kb

input:

15 12 196428923

output:

29322522

result:

ok single line: '29322522'

Test #9:

score: 0
Accepted
time: 11ms
memory: 8128kb

input:

68 7 786815587

output:

149281835

result:

ok single line: '149281835'

Test #10:

score: 0
Accepted
time: 0ms
memory: 5780kb

input:

3 2 503002109

output:

82

result:

ok single line: '82'

Test #11:

score: 0
Accepted
time: 1ms
memory: 5876kb

input:

13 5 756093197

output:

415698676

result:

ok single line: '415698676'

Test #12:

score: 0
Accepted
time: 1ms
memory: 5580kb

input:

2 3 646574611

output:

30

result:

ok single line: '30'

Test #13:

score: 0
Accepted
time: 75ms
memory: 21204kb

input:

39 68 120037189

output:

43217507

result:

ok single line: '43217507'

Test #14:

score: 0
Accepted
time: 1ms
memory: 5936kb

input:

13 4 423132517

output:

360231790

result:

ok single line: '360231790'

Test #15:

score: 0
Accepted
time: 1ms
memory: 5876kb

input:

14 3 309713387

output:

94215386

result:

ok single line: '94215386'

Test #16:

score: 0
Accepted
time: 35ms
memory: 17516kb

input:

24 77 886983941

output:

211636479

result:

ok single line: '211636479'

Test #17:

score: 0
Accepted
time: 1ms
memory: 5760kb

input:

3 3 504388063

output:

270

result:

ok single line: '270'

Test #18:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

3 1 936205423

output:

8

result:

ok single line: '8'

Test #19:

score: 0
Accepted
time: 1ms
memory: 5772kb

input:

3 3 295983139

output:

270

result:

ok single line: '270'

Test #20:

score: 0
Accepted
time: 1ms
memory: 8372kb

input:

10 15 446169107

output:

149884328

result:

ok single line: '149884328'

Test #21:

score: 0
Accepted
time: 4ms
memory: 8612kb

input:

37 18 833753929

output:

592917251

result:

ok single line: '592917251'

Test #22:

score: 0
Accepted
time: 1ms
memory: 5720kb

input:

11 3 998773403

output:

860630017

result:

ok single line: '860630017'

Test #23:

score: 0
Accepted
time: 13ms
memory: 14580kb

input:

14 85 688036639

output:

347188409

result:

ok single line: '347188409'

Test #24:

score: 0
Accepted
time: 1ms
memory: 5764kb

input:

3 3 844621907

output:

270

result:

ok single line: '270'

Test #25:

score: 0
Accepted
time: 1ms
memory: 5740kb

input:

3 4 204335891

output:

620

result:

ok single line: '620'

Test #26:

score: 0
Accepted
time: 1ms
memory: 5816kb

input:

7 8 113007667

output:

58946097

result:

ok single line: '58946097'

Test #27:

score: 0
Accepted
time: 1ms
memory: 5616kb

input:

4 1 637268377

output:

22

result:

ok single line: '22'

Test #28:

score: 0
Accepted
time: 0ms
memory: 6336kb

input:

11 14 391637237

output:

303270280

result:

ok single line: '303270280'

Test #29:

score: 0
Accepted
time: 0ms
memory: 5572kb

input:

3 2 208286231

output:

82

result:

ok single line: '82'

Test #30:

score: 0
Accepted
time: 1ms
memory: 5792kb

input:

2 11 662696483

output:

462

result:

ok single line: '462'

Test #31:

score: 0
Accepted
time: 10ms
memory: 12304kb

input:

19 55 974135299

output:

887460557

result:

ok single line: '887460557'

Test #32:

score: 0
Accepted
time: 0ms
memory: 5968kb

input:

6 8 417027509

output:

23351024

result:

ok single line: '23351024'

Test #33:

score: 0
Accepted
time: 1ms
memory: 6196kb

input:

8 13 624006587

output:

353008442

result:

ok single line: '353008442'

Test #34:

score: 0
Accepted
time: 0ms
memory: 8076kb

input:

10 10 740294671

output:

79436611

result:

ok single line: '79436611'

Test #35:

score: 0
Accepted
time: 1ms
memory: 6156kb

input:

11 10 394088657

output:

161476458

result:

ok single line: '161476458'

Test #36:

score: 0
Accepted
time: 2ms
memory: 8840kb

input:

9 27 562853573

output:

135252259

result:

ok single line: '135252259'

Test #37:

score: 0
Accepted
time: 1ms
memory: 7760kb

input:

8 3 829129009

output:

5349034

result:

ok single line: '5349034'

Test #38:

score: 0
Accepted
time: 79ms
memory: 19024kb

input:

51 49 924010279

output:

815049368

result:

ok single line: '815049368'

Test #39:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

12 2 308466749

output:

223013998

result:

ok single line: '223013998'

Test #40:

score: 0
Accepted
time: 1ms
memory: 5688kb

input:

7 4 567557693

output:

4502296

result:

ok single line: '4502296'

Test #41:

score: 0
Accepted
time: 115ms
memory: 23884kb

input:

36 93 943780729

output:

13599465

result:

ok single line: '13599465'

Test #42:

score: 0
Accepted
time: 1ms
memory: 5732kb

input:

2 1 828681127

output:

2

result:

ok single line: '2'

Test #43:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

3 3 534160729

output:

270

result:

ok single line: '270'

Test #44:

score: 0
Accepted
time: 1ms
memory: 6076kb

input:

7 12 920925433

output:

453086694

result:

ok single line: '453086694'

Test #45:

score: 0
Accepted
time: 1ms
memory: 5756kb

input:

3 2 440546987

output:

82

result:

ok single line: '82'

Test #46:

score: 0
Accepted
time: 30ms
memory: 9872kb

input:

90 9 291269963

output:

72560304

result:

ok single line: '72560304'

Test #47:

score: 0
Accepted
time: 5ms
memory: 9560kb

input:

38 10 867575113

output:

165530481

result:

ok single line: '165530481'

Test #48:

score: 0
Accepted
time: 45ms
memory: 15684kb

input:

48 37 152663531

output:

135425620

result:

ok single line: '135425620'

Test #49:

score: 0
Accepted
time: 2ms
memory: 6704kb

input:

15 15 991731803

output:

102703562

result:

ok single line: '102703562'

Test #50:

score: 0
Accepted
time: 1311ms
memory: 57924kb

input:

100 100 696969697

output:

313377809

result:

ok single line: '313377809'

Extra Test:

score: 0
Extra Test Passed