QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#884792#9782. NonZero PrefSuf Sumsphelixzhen_falseAC ✓822ms19840kbC++262.7kb2025-02-06 10:49:262025-02-06 10:49:27

Judging History

This is the latest submission verdict.

  • [2025-02-06 10:49:27]
  • Judged
  • Verdict: AC
  • Time: 822ms
  • Memory: 19840kb
  • [2025-02-06 10:49:26]
  • Submitted

answer

#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class T>
void operator +=(vec<T> &a,T b){a.push_back(b);}
template<class T>
void operator --(vec<T> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1e18)
template<class T>
bool Min(T &x,T y){return x>y?x=y,1:0;}
template<class T>
bool Max(T &x,T y){return x<y?x=y,1:0;}
int mod;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
    int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}
const int D=10000;

int n,m,ans;
int f[110][20110],g[20110];
void sol(int m,int* f){
    f[D]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=2*D+m;j++){
            g[j]=f[j];
            if(j)Add(g[j],g[j-1]);
        }
        for(int j=2*D;j;j--){
            f[j]=f[j-1];
        }
        f[0]=0;
        for(int j=0;j<=2*D;j++){
            Add(f[j],g[j+m]);
            if(j)Add(f[j],mod-g[j-1]);
        }
    }
}
void sol2(int* f){
    f[D]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=2*D+m;j++){
            g[j]=f[j];
            if(j)Add(g[j],g[j-1]);
        }
        for(int j=0;j<=2*D;j++){
            f[j]=g[j+m];
            if(j>m){
                Add(f[j],mod-g[j-m-1]);
            }
        }
    }
    Add(ans,f[D]);
}
void work(){
    cin>>n>>m>>mod;

    for(int i=-1;i<=m;i++){
        sol(i,f[i+1]);
    }

    for(int p=1;p<=m;p++){
        // max negative>=sum-1
        // sum>0
        // max negative<=m/p

        //p,2p,3p,...

        for(int s=D+1;s<=D*2;s++){
            Add(ans,f[m/p+1][s]);
        }

        for(int s=1;s<=n*m;s++){
            Add(ans,mod-f[min(m/p,s-2)+1][s+D]);
        }
    }

    (ans*=2)%=mod;

    sol2(f[m+2]);


    cout<<(fpm(2*m+1,n)+mod-ans%mod)%mod<<'\n';
}
bool Med;
signed main(){
    ios::sync_with_stdio(0),
    cin.tie(0),cout.tie(0);
    int T=1;while(T--)work();
    // cerr<<"Time: "<<clock()<<" ms;\n";
    // cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 224ms
memory: 11056kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #3:

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

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 227ms
memory: 10848kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #5:

score: 0
Accepted
time: 357ms
memory: 15976kb

input:

61 75 677323601

output:

34613998

result:

ok single line: '34613998'

Test #6:

score: 0
Accepted
time: 15ms
memory: 6728kb

input:

13 14 670577333

output:

41465431

result:

ok single line: '41465431'

Test #7:

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

input:

14 6 987686347

output:

37536510

result:

ok single line: '37536510'

Test #8:

score: 0
Accepted
time: 15ms
memory: 6272kb

input:

15 12 196428923

output:

29322522

result:

ok single line: '29322522'

Test #9:

score: 0
Accepted
time: 49ms
memory: 5376kb

input:

68 7 786815587

output:

149281835

result:

ok single line: '149281835'

Test #10:

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

input:

3 2 503002109

output:

82

result:

ok single line: '82'

Test #11:

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

input:

13 5 756093197

output:

415698676

result:

ok single line: '415698676'

Test #12:

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

input:

2 3 646574611

output:

30

result:

ok single line: '30'

Test #13:

score: 0
Accepted
time: 200ms
memory: 16100kb

input:

39 68 120037189

output:

43217507

result:

ok single line: '43217507'

Test #14:

score: 0
Accepted
time: 6ms
memory: 6520kb

input:

13 4 423132517

output:

360231790

result:

ok single line: '360231790'

Test #15:

score: 0
Accepted
time: 6ms
memory: 4736kb

input:

14 3 309713387

output:

94215386

result:

ok single line: '94215386'

Test #16:

score: 0
Accepted
time: 138ms
memory: 16396kb

input:

24 77 886983941

output:

211636479

result:

ok single line: '211636479'

Test #17:

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

input:

3 3 504388063

output:

270

result:

ok single line: '270'

Test #18:

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

input:

3 1 936205423

output:

8

result:

ok single line: '8'

Test #19:

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

input:

3 3 295983139

output:

270

result:

ok single line: '270'

Test #20:

score: 0
Accepted
time: 14ms
memory: 6784kb

input:

10 15 446169107

output:

149884328

result:

ok single line: '149884328'

Test #21:

score: 0
Accepted
time: 55ms
memory: 7936kb

input:

37 18 833753929

output:

592917251

result:

ok single line: '592917251'

Test #22:

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

input:

11 3 998773403

output:

860630017

result:

ok single line: '860630017'

Test #23:

score: 0
Accepted
time: 87ms
memory: 17656kb

input:

14 85 688036639

output:

347188409

result:

ok single line: '347188409'

Test #24:

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

input:

3 3 844621907

output:

270

result:

ok single line: '270'

Test #25:

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

input:

3 4 204335891

output:

620

result:

ok single line: '620'

Test #26:

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

input:

7 8 113007667

output:

58946097

result:

ok single line: '58946097'

Test #27:

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

input:

4 1 637268377

output:

22

result:

ok single line: '22'

Test #28:

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

input:

11 14 391637237

output:

303270280

result:

ok single line: '303270280'

Test #29:

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

input:

3 2 208286231

output:

82

result:

ok single line: '82'

Test #30:

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

input:

2 11 662696483

output:

462

result:

ok single line: '462'

Test #31:

score: 0
Accepted
time: 78ms
memory: 12992kb

input:

19 55 974135299

output:

887460557

result:

ok single line: '887460557'

Test #32:

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

input:

6 8 417027509

output:

23351024

result:

ok single line: '23351024'

Test #33:

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

input:

8 13 624006587

output:

353008442

result:

ok single line: '353008442'

Test #34:

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

input:

10 10 740294671

output:

79436611

result:

ok single line: '79436611'

Test #35:

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

input:

11 10 394088657

output:

161476458

result:

ok single line: '161476458'

Test #36:

score: 0
Accepted
time: 17ms
memory: 8448kb

input:

9 27 562853573

output:

135252259

result:

ok single line: '135252259'

Test #37:

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

input:

8 3 829129009

output:

5349034

result:

ok single line: '5349034'

Test #38:

score: 0
Accepted
time: 193ms
memory: 11984kb

input:

51 49 924010279

output:

815049368

result:

ok single line: '815049368'

Test #39:

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

input:

12 2 308466749

output:

223013998

result:

ok single line: '223013998'

Test #40:

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

input:

7 4 567557693

output:

4502296

result:

ok single line: '4502296'

Test #41:

score: 0
Accepted
time: 258ms
memory: 18924kb

input:

36 93 943780729

output:

13599465

result:

ok single line: '13599465'

Test #42:

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

input:

2 1 828681127

output:

2

result:

ok single line: '2'

Test #43:

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

input:

3 3 534160729

output:

270

result:

ok single line: '270'

Test #44:

score: 0
Accepted
time: 7ms
memory: 7584kb

input:

7 12 920925433

output:

453086694

result:

ok single line: '453086694'

Test #45:

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

input:

3 2 440546987

output:

82

result:

ok single line: '82'

Test #46:

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

input:

90 9 291269963

output:

72560304

result:

ok single line: '72560304'

Test #47:

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

input:

38 10 867575113

output:

165530481

result:

ok single line: '165530481'

Test #48:

score: 0
Accepted
time: 138ms
memory: 9984kb

input:

48 37 152663531

output:

135425620

result:

ok single line: '135425620'

Test #49:

score: 0
Accepted
time: 19ms
memory: 7208kb

input:

15 15 991731803

output:

102703562

result:

ok single line: '102703562'

Test #50:

score: 0
Accepted
time: 822ms
memory: 19840kb

input:

100 100 696969697

output:

313377809

result:

ok single line: '313377809'

Extra Test:

score: 0
Extra Test Passed