QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#812891#9782. NonZero PrefSuf Sumsucup-team135#AC ✓573ms31024kbC++206.0kb2024-12-13 19:16:382024-12-13 19:16:39

Judging History

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

  • [2024-12-13 19:16:39]
  • 评测
  • 测评结果:AC
  • 用时:573ms
  • 内存:31024kb
  • [2024-12-13 19:16:38]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
#include <array>
#include <functional>
#include <stack>
#include <memory>
using namespace std;
#define int long long
int p;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}}
int inv(int x) {return po(x,p-2);}
mt19937 rnd;
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#define debugv(v) do {cout<< #v <<" : {"; for(int izxc=0;izxc<v.size();++izxc) {cout << v[izxc];if(izxc+1!=v.size()) cout << ","; }cout <<"}"<< endl;} while(0)
#else
#define debug(...)
#define debugv(v)
#endif
#define lob(a,x) lower_bound(all(a),x)
#define upb(a,x) upper_bound(all(a),x)
const int maxn=1005;
int fact[maxn];int invf[maxn];
int n,m;
int C(int a,int b,int c)
{
    int ans=fact[a+b+c];ans*=invf[a];ans%=p;ans*=invf[b];ans%=p;ans*=invf[c];ans%=p;
    return ans;
}
const int maxs=1e4+1005;
int dps[2*maxs];int dps2[2*maxs];
bool check(vector<int> v)
{
    int s=accumulate(all(v),0LL);
    if(s==0) {return false;}
    int non0=0;for(int x:v) if(x) non0++;
    if(non0<=1) {return false;}
    int d=0;
    for(int x:v) d=__gcd(d,x);
    d=abs(d);
    for(int &x:v) {x/=d;}
    vector<int> vp,vm;
    for(int x:v) if(x>0) vp.app(x);
    for(int x:v) if(x<0) vm.app(x);
    if(count(all(vp),1)==vp.size()) return true;
    if(count(all(vm),-1)==vm.size()) return true;
    sort(all(v));
    vector<int> pr(v.size()+1);
    do
    {
        for(int i=0;i<v.size();++i) {pr[i+1]=pr[i]+v[i];}
        bool ok=1;
        for(int i=1;i<v.size();++i)
        {
            if(pr[i]==0 || pr[i]==s)
            {
                ok=0;
            }
        }
        if(ok) return true;
    }while(next_permutation(all(v)));
    debugv(v);
    return false;
}
bool real(vector<int> v)
{
    int s=accumulate(all(v),0LL);
    if(s==0) {return false;}
    int non0=0;for(int x:v) if(x) non0++;
    if(non0<=1) {return false;}
    sort(all(v));
    vector<int> pr(v.size()+1);
    do
    {
        for(int i=0;i<v.size();++i) {pr[i+1]=pr[i]+v[i];}
        bool ok=1;
        for(int i=1;i<v.size();++i)
        {
            if(pr[i]==0 || pr[i]==s)
            {
                ok=0;
            }
        }
        if(ok) return true;
    }while(next_permutation(all(v)));
    return false;
}
vector<vector<int> >  go(int n,int m)
{
    if(n==0) {return {{}};}
    vector<vector<int> > was=go(n-1,m);
    vector<vector<int> > have;
    for(vector<int> h:was)
    {
        for(int x=-m;x<=m;++x)
        {
            vector<int> h1=h;
            h1.app(x);
            if(!is_sorted(all(h1))) continue;
            have.app(h1);
        }
    }
    return have;
}
vector<vector<int> >  go2(int n,int m)
{
    if(n==0) {return {{}};}
    vector<vector<int> > was=go2(n-1,m);
    vector<vector<int> > have;
    for(vector<int> h:was)
    {
        for(int x=-m;x<=m;++x)
        {
            vector<int> h1=h;
            h1.app(x);
            have.app(h1);
        }
    }
    return have;
}
int stupid(int n,int m)
{
    vector<vector<int> > h=go2(n,m);
    debug(h.size());
    int ans=0;int cnt=0;
    for(auto v:h)
    {
        if(!real(v) && accumulate(all(v),0LL)) {++cnt;debugv(v);}
        ans+=real(v);
    }
    debug(cnt);
    return ans;
}
const int maxn1=105;
int dp1[3*maxn1][maxn1][maxn1];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    /*vector<vector<int> > aa=go(10,4);vector<vector<int> > aas;
    for(auto hh:aa) {sort(all(hh));aas.app(hh);}
    sort(all(aas));aas.erase(unique(all(aas)),aas.end());
    for(auto v:aas) {check(v);}
    debug("okk");*/
    cin>>n>>m>>p;
    //debug(stupid(n,m));
    fact[0]=1;for(int i=1;i<maxn;++i) {fact[i]=(fact[i-1]*i)%p;}
    for(int i=0;i<maxn;++i) {invf[i]=inv(fact[i]);}
    int al=po(2*m+1,n);
    int bad=2*n*m;bad%=p;
    dps[maxs]=1;
    for(int i=0;i<n;++i)
    {
        fill(dps2,dps2+2*maxs,0);
        for(int j=-m;j<=m;++j)
        {
            for(int s1=0;s1<2*maxs;++s1)
            {
                if(dps[s1])
                {
                    dps2[s1+j]+=dps[s1];if(dps2[s1+j]>=p) dps2[s1+j]-=p;
                }
            }
        }
        copy(dps2,dps2+2*maxs,dps);
    }
    bad+=dps[maxs];bad%=p;
    debug(bad);
    dp1[0][0][0]=1;
    debug("regrf");
    for(int mx=1;mx<=m;++mx)
    {
        for(int s=0;s<3*maxn1-mx;++s)
        {
            for(int n=0;n<maxn1;++n)
            {
                dp1[s][mx][n]+=dp1[s][mx-1][n];if(dp1[s][mx][n]>=p) dp1[s][mx][n]-=p;
            }
        }
        for(int s=3*maxn1-mx;s>=0;--s)
        {
            for(int cnt=1;cnt*mx+s<3*maxn1;++cnt) {
            for(int n=0;n<maxn1;++n)
            {
                dp1[s+cnt*mx][mx][n+cnt]+=(dp1[s][mx][n]*invf[cnt]);dp1[s+cnt*mx][mx][n+cnt]%=p;
            }
            }
        }
    }
    debug(dp1[1][1][1]);
    debug("rgef");
    int bad1=0;
    for(int np=0;np<=n;++np)
    {
        for(int s=1;s<np;++s)
        {
            for(int n0=0;n0<n-np;++n0) {
            int nm=n-n0-np;
            for(int mx=max(1LL,s-1);mx<=m;++mx)
            {
                int o=((2*(m/mx)*1LL*(dp1[np-s][mx][nm]-dp1[np-s][mx-1][nm]))%p);
                o*=fact[n];o%=p;
                o*=invf[np];o%=p;
                o*=invf[n0];o%=p;
                bad+=o;bad%=p;
                bad1+=o;bad1%=p;
            }
            }
        }
    }
    debug(bad1);
    cout<<((al-bad)%p+p)%p;
    return 0;
}

















詳細信息

Test #1:

score: 100
Accepted
time: 17ms
memory: 5744kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 165ms
memory: 17412kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #3:

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

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 174ms
memory: 17060kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #5:

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

input:

61 75 677323601

output:

34613998

result:

ok single line: '34613998'

Test #6:

score: 0
Accepted
time: 57ms
memory: 10708kb

input:

13 14 670577333

output:

41465431

result:

ok single line: '41465431'

Test #7:

score: 0
Accepted
time: 42ms
memory: 7024kb

input:

14 6 987686347

output:

37536510

result:

ok single line: '37536510'

Test #8:

score: 0
Accepted
time: 43ms
memory: 8512kb

input:

15 12 196428923

output:

29322522

result:

ok single line: '29322522'

Test #9:

score: 0
Accepted
time: 48ms
memory: 7276kb

input:

68 7 786815587

output:

149281835

result:

ok single line: '149281835'

Test #10:

score: 0
Accepted
time: 25ms
memory: 5892kb

input:

3 2 503002109

output:

82

result:

ok single line: '82'

Test #11:

score: 0
Accepted
time: 38ms
memory: 6568kb

input:

13 5 756093197

output:

415698676

result:

ok single line: '415698676'

Test #12:

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

input:

2 3 646574611

output:

30

result:

ok single line: '30'

Test #13:

score: 0
Accepted
time: 162ms
memory: 22800kb

input:

39 68 120037189

output:

43217507

result:

ok single line: '43217507'

Test #14:

score: 0
Accepted
time: 27ms
memory: 7888kb

input:

13 4 423132517

output:

360231790

result:

ok single line: '360231790'

Test #15:

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

input:

14 3 309713387

output:

94215386

result:

ok single line: '94215386'

Test #16:

score: 0
Accepted
time: 136ms
memory: 25112kb

input:

24 77 886983941

output:

211636479

result:

ok single line: '211636479'

Test #17:

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

input:

3 3 504388063

output:

270

result:

ok single line: '270'

Test #18:

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

input:

3 1 936205423

output:

8

result:

ok single line: '8'

Test #19:

score: 0
Accepted
time: 26ms
memory: 6304kb

input:

3 3 295983139

output:

270

result:

ok single line: '270'

Test #20:

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

input:

10 15 446169107

output:

149884328

result:

ok single line: '149884328'

Test #21:

score: 0
Accepted
time: 67ms
memory: 9860kb

input:

37 18 833753929

output:

592917251

result:

ok single line: '592917251'

Test #22:

score: 0
Accepted
time: 27ms
memory: 6004kb

input:

11 3 998773403

output:

860630017

result:

ok single line: '860630017'

Test #23:

score: 0
Accepted
time: 102ms
memory: 27104kb

input:

14 85 688036639

output:

347188409

result:

ok single line: '347188409'

Test #24:

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

input:

3 3 844621907

output:

270

result:

ok single line: '270'

Test #25:

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

input:

3 4 204335891

output:

620

result:

ok single line: '620'

Test #26:

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

input:

7 8 113007667

output:

58946097

result:

ok single line: '58946097'

Test #27:

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

input:

4 1 637268377

output:

22

result:

ok single line: '22'

Test #28:

score: 0
Accepted
time: 52ms
memory: 8816kb

input:

11 14 391637237

output:

303270280

result:

ok single line: '303270280'

Test #29:

score: 0
Accepted
time: 25ms
memory: 5964kb

input:

3 2 208286231

output:

82

result:

ok single line: '82'

Test #30:

score: 0
Accepted
time: 41ms
memory: 8132kb

input:

2 11 662696483

output:

462

result:

ok single line: '462'

Test #31:

score: 0
Accepted
time: 90ms
memory: 19464kb

input:

19 55 974135299

output:

887460557

result:

ok single line: '887460557'

Test #32:

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

input:

6 8 417027509

output:

23351024

result:

ok single line: '23351024'

Test #33:

score: 0
Accepted
time: 54ms
memory: 8440kb

input:

8 13 624006587

output:

353008442

result:

ok single line: '353008442'

Test #34:

score: 0
Accepted
time: 42ms
memory: 7828kb

input:

10 10 740294671

output:

79436611

result:

ok single line: '79436611'

Test #35:

score: 0
Accepted
time: 50ms
memory: 9400kb

input:

11 10 394088657

output:

161476458

result:

ok single line: '161476458'

Test #36:

score: 0
Accepted
time: 66ms
memory: 12168kb

input:

9 27 562853573

output:

135252259

result:

ok single line: '135252259'

Test #37:

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

input:

8 3 829129009

output:

5349034

result:

ok single line: '5349034'

Test #38:

score: 0
Accepted
time: 143ms
memory: 17812kb

input:

51 49 924010279

output:

815049368

result:

ok single line: '815049368'

Test #39:

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

input:

12 2 308466749

output:

223013998

result:

ok single line: '223013998'

Test #40:

score: 0
Accepted
time: 34ms
memory: 7976kb

input:

7 4 567557693

output:

4502296

result:

ok single line: '4502296'

Test #41:

score: 0
Accepted
time: 174ms
memory: 29272kb

input:

36 93 943780729

output:

13599465

result:

ok single line: '13599465'

Test #42:

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

input:

2 1 828681127

output:

2

result:

ok single line: '2'

Test #43:

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

input:

3 3 534160729

output:

270

result:

ok single line: '270'

Test #44:

score: 0
Accepted
time: 48ms
memory: 8248kb

input:

7 12 920925433

output:

453086694

result:

ok single line: '453086694'

Test #45:

score: 0
Accepted
time: 25ms
memory: 7536kb

input:

3 2 440546987

output:

82

result:

ok single line: '82'

Test #46:

score: 0
Accepted
time: 73ms
memory: 7592kb

input:

90 9 291269963

output:

72560304

result:

ok single line: '72560304'

Test #47:

score: 0
Accepted
time: 58ms
memory: 7804kb

input:

38 10 867575113

output:

165530481

result:

ok single line: '165530481'

Test #48:

score: 0
Accepted
time: 102ms
memory: 15008kb

input:

48 37 152663531

output:

135425620

result:

ok single line: '135425620'

Test #49:

score: 0
Accepted
time: 59ms
memory: 9112kb

input:

15 15 991731803

output:

102703562

result:

ok single line: '102703562'

Test #50:

score: 0
Accepted
time: 573ms
memory: 31024kb

input:

100 100 696969697

output:

313377809

result:

ok single line: '313377809'

Extra Test:

score: 0
Extra Test Passed