QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#904244#9782. NonZero PrefSuf Sumsi_am_noobAC ✓9ms30972kbC++142.6kb2025-02-18 01:24:322025-02-18 01:24:32

Judging History

This is the latest submission verdict.

  • [2025-02-18 01:24:32]
  • Judged
  • Verdict: AC
  • Time: 9ms
  • Memory: 30972kb
  • [2025-02-18 01:24:32]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using pii=pair<int,int>;
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define pb push_back

const int N=105;
int mod;

int add(int x, int y){
    x+=y; if(x>=mod) x-=mod;
    return x;
}
int sub(int x, int y){
    x-=y; if(x<0) x+=mod;
    return x;
}
int mul(int x, int y){
    return ((ll)x)*y%mod;
}
int Pow(int x, ll y){
    int res=1;
    for(; y; x=mul(x,x),y>>=1) if(y&1) res=mul(res,x);
    return res;
}

int n,m,C[N][N],dp[N][N*N*2],sum[N][N*N*2],dp2[N][N][N],sum2[N][N][N];

void build_dp(int mx){
    memset(dp,0,sizeof dp);
    memset(sum,0,sizeof sum);
    dp[0][0]=1;
    for(int i=0; i<N*N*2; ++i) sum[0][i]=1;
    for(int i=1; i<=n; ++i){
        for(int j=0; j<=mx*i; ++j){
            dp[i][j]=sum[i-1][j];
            if(j-mx-1>=0) dp[i][j]=sub(dp[i][j],sum[i-1][j-mx-1]);
        }
        sum[i][0]=dp[i][0];
        for(int j=1; j<=mx*(i+1); ++j){
            sum[i][j]=add(sum[i][j-1],dp[i][j]);
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m >> mod;
    C[0][0]=1;
    for(int i=1; i<N; ++i){
        for(int j=0; j<=i; ++j){
            if(j==0||j==i) C[i][j]=1;
            else C[i][j]=add(C[i-1][j-1],C[i-1][j]);
        }
    }
    int res=Pow(2*m+1,n);
    build_dp(m*2);
    for(int mx=0; mx<=n; ++mx){
        dp2[mx][0][0]=1;
        for(int i=0; i<N; ++i) sum2[mx][0][i]=1;
        for(int i=1; i<=n; ++i){
            for(int j=0; j<=n; ++j){
                dp2[mx][i][j]=sum2[mx][i-1][j];
                if(j-mx-1>=0) dp2[mx][i][j]=sub(dp2[mx][i][j],sum2[mx][i-1][j-mx-1]);
            }
            sum2[mx][i][0]=dp2[mx][i][0];
            for(int j=1; j<=n; ++j){
                sum2[mx][i][j]=add(sum2[mx][i][j-1],dp2[mx][i][j]);
            }
        }
    }
    for(int mx=n; mx>=1; --mx){
        for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) dp2[mx][i][j]=sub(dp2[mx][i][j],dp2[mx-1][i][j]);
    }
    res=sub(res,dp[n][n*m]);
    //cout << res << "\n";
    for(int x=1; x<=m; ++x){
        int y=x;
        while(y+1<=m&&m/(y+1)==m/x) y++;
        int tot=0;
        for(int mx=0; mx<=m/x; ++mx){
            for(int i=0; i<n; ++i){
                for(int j=0; j<=n; ++j) if(j<n-i){
                    if(j+mx+2>n-i){
                        tot=add(tot,mul(C[n][i],dp2[mx][i][j]));
                        //cout << mx << ' ' << i << ' ' << j << ' ' << dp2[mx][i][j] << "\n";
                    }
                }
            }
        }
        res=sub(res,mul(tot,2*(y-x+1)));
        x=y;
    }
    cout << res << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 23968kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #2:

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

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #3:

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

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 3ms
memory: 30792kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #5:

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

input:

61 75 677323601

output:

34613998

result:

ok single line: '34613998'

Test #6:

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

input:

13 14 670577333

output:

41465431

result:

ok single line: '41465431'

Test #7:

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

input:

14 6 987686347

output:

37536510

result:

ok single line: '37536510'

Test #8:

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

input:

15 12 196428923

output:

29322522

result:

ok single line: '29322522'

Test #9:

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

input:

68 7 786815587

output:

149281835

result:

ok single line: '149281835'

Test #10:

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

input:

3 2 503002109

output:

82

result:

ok single line: '82'

Test #11:

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

input:

13 5 756093197

output:

415698676

result:

ok single line: '415698676'

Test #12:

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

input:

2 3 646574611

output:

30

result:

ok single line: '30'

Test #13:

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

input:

39 68 120037189

output:

43217507

result:

ok single line: '43217507'

Test #14:

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

input:

13 4 423132517

output:

360231790

result:

ok single line: '360231790'

Test #15:

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

input:

14 3 309713387

output:

94215386

result:

ok single line: '94215386'

Test #16:

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

input:

24 77 886983941

output:

211636479

result:

ok single line: '211636479'

Test #17:

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

input:

3 3 504388063

output:

270

result:

ok single line: '270'

Test #18:

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

input:

3 1 936205423

output:

8

result:

ok single line: '8'

Test #19:

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

input:

3 3 295983139

output:

270

result:

ok single line: '270'

Test #20:

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

input:

10 15 446169107

output:

149884328

result:

ok single line: '149884328'

Test #21:

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

input:

37 18 833753929

output:

592917251

result:

ok single line: '592917251'

Test #22:

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

input:

11 3 998773403

output:

860630017

result:

ok single line: '860630017'

Test #23:

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

input:

14 85 688036639

output:

347188409

result:

ok single line: '347188409'

Test #24:

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

input:

3 3 844621907

output:

270

result:

ok single line: '270'

Test #25:

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

input:

3 4 204335891

output:

620

result:

ok single line: '620'

Test #26:

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

input:

7 8 113007667

output:

58946097

result:

ok single line: '58946097'

Test #27:

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

input:

4 1 637268377

output:

22

result:

ok single line: '22'

Test #28:

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

input:

11 14 391637237

output:

303270280

result:

ok single line: '303270280'

Test #29:

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

input:

3 2 208286231

output:

82

result:

ok single line: '82'

Test #30:

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

input:

2 11 662696483

output:

462

result:

ok single line: '462'

Test #31:

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

input:

19 55 974135299

output:

887460557

result:

ok single line: '887460557'

Test #32:

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

input:

6 8 417027509

output:

23351024

result:

ok single line: '23351024'

Test #33:

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

input:

8 13 624006587

output:

353008442

result:

ok single line: '353008442'

Test #34:

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

input:

10 10 740294671

output:

79436611

result:

ok single line: '79436611'

Test #35:

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

input:

11 10 394088657

output:

161476458

result:

ok single line: '161476458'

Test #36:

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

input:

9 27 562853573

output:

135252259

result:

ok single line: '135252259'

Test #37:

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

input:

8 3 829129009

output:

5349034

result:

ok single line: '5349034'

Test #38:

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

input:

51 49 924010279

output:

815049368

result:

ok single line: '815049368'

Test #39:

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

input:

12 2 308466749

output:

223013998

result:

ok single line: '223013998'

Test #40:

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

input:

7 4 567557693

output:

4502296

result:

ok single line: '4502296'

Test #41:

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

input:

36 93 943780729

output:

13599465

result:

ok single line: '13599465'

Test #42:

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

input:

2 1 828681127

output:

2

result:

ok single line: '2'

Test #43:

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

input:

3 3 534160729

output:

270

result:

ok single line: '270'

Test #44:

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

input:

7 12 920925433

output:

453086694

result:

ok single line: '453086694'

Test #45:

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

input:

3 2 440546987

output:

82

result:

ok single line: '82'

Test #46:

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

input:

90 9 291269963

output:

72560304

result:

ok single line: '72560304'

Test #47:

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

input:

38 10 867575113

output:

165530481

result:

ok single line: '165530481'

Test #48:

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

input:

48 37 152663531

output:

135425620

result:

ok single line: '135425620'

Test #49:

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

input:

15 15 991731803

output:

102703562

result:

ok single line: '102703562'

Test #50:

score: 0
Accepted
time: 9ms
memory: 30972kb

input:

100 100 696969697

output:

313377809

result:

ok single line: '313377809'

Extra Test:

score: 0
Extra Test Passed