QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#431875#8015. 鸡Williamxzh100 ✓1ms3956kbC++231.8kb2024-06-06 11:24:242024-06-06 11:24:25

Judging History

This is the latest submission verdict.

  • [2024-06-06 11:24:25]
  • Judged
  • Verdict: 100
  • Time: 1ms
  • Memory: 3956kb
  • [2024-06-06 11:24:24]
  • Submitted

answer

#include <bits/stdc++.h>
#define il inline
using namespace std;
typedef long long ll;
ll mod;
il ll qp(ll a,ll b){
    ll ans=1ll;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod,b>>=1;
    }return ans;
}
il ll v(ll a,ll b){return (a*qp(b,mod-2ll))%mod;}
const int N=3005;
ll f1[N]={0,1,4,6,12,19,35,58,102,172,296,501,853,1442};
ll f2[N]={0,1,9,17,47,94,227,477,1073,2290,4985,10637,22779};
ll f3[N]={0,1,16,36,120,281,803,1960};
ll f4[N]={0,1,25,65,245,649,2089,5705};
ll f5[N]={0,1,36,106,436,1281,4511,13506};
ll f6[N]={0,1,49,0,0,2274,8595,27853};
ll f7[N]={0,0,0,0,0,0,14967,52032};
ll f8[N]={0,0,0,0,0,0,0,90225};
int n,m,k;ll f[N],p[N],a[N];
ll x,y,z;
int main(){
    //freopen("c_1.in","r",stdin);
    scanf("%d%d%lld",&n,&m,&mod);

    p[0]=1ll;for(int i=1;i<=7;++i) p[i]=(p[i-1]*1ll*m)%mod;

    f[1]=1ll;
    f[2]=(m+1ll)*(m+1ll)%mod;
    f[3]=v(1,3)*p[3]+2ll*p[2]+v(8,3)*p[1]+1ll;
    f[4]=v(7,3)*p[3]+5ll*p[2]+v(11,3)*p[1]+1ll;
    f[5]=v(7,12)*p[4]+v(17,3)*p[3]+v(89,12)*p[2]+v(13,3)*p[1]+1ll;
    f[6]=v(25,6)*p[4]+v(38,3)*p[3]+v(71,6)*p[2]+v(16,3)*p[1]+1ll;
    f[7]=v(5,6)*p[5]+v(37,3)*p[4]+v(133,6)*p[3]+v(47,3)*p[2]+6*p[1]+1ll;

    for(int i=1;i<=7;++i) f[i]%=mod;

    a[1]=2ll,a[2]=2ll*m,a[3]=-2ll*(m+1ll),a[4]=(2ll-f[2]),a[5]=2ll*m,a[6]=m*m;
    for(int i=1;i<=6;++i) a[i]=(a[i]%mod+mod)%mod;

    for(int i=8;i<=n;++i)
        for(int j=1;j<=6;++j) f[i]=(f[i]+f[i-j]*a[j])%mod;

    printf("%lld",f[n]);
    return 0;
}
/*
1,4,6,12,19,35,58,102,296,501
2,2,3,3,4,4,5,5,6,6
0,2,3,9,15,31,53,97,290,495

1,4,6,12,19,35,58,102,172,296,501,853,1442
1,9,17,47,94,227,477,1073,2290,4985,10637,22779

g(1,x)=1
g(2,x)=x^2+2x+1

2,2,−4,−2,2,1)
m=2m=2m=2:(2,4,−6,−7,4,4)(2,4,-6,-7,4,4)(2,4,−6,−7,4,4)
m=3m=3m=3:(2,6,−8,−14,6,9)(2,6,-8,-14,6,9)(2,6,−8,−14,6,9)
*/


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 1ms
memory: 3876kb

input:

5 5 1004326439

output:

1281

result:

ok 1 number(s): "1281"

Test #2:

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

input:

5 4 1002682123

output:

649

result:

ok 1 number(s): "649"

Test #3:

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

input:

287 1 1003060133

output:

328406329

result:

ok 1 number(s): "328406329"

Test #4:

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

input:

279 1 1004432189

output:

222258837

result:

ok 1 number(s): "222258837"

Test #5:

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

input:

300 1 1005912203

output:

707086810

result:

ok 1 number(s): "707086810"

Test #6:

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

input:

288 5 1003307827

output:

964512417

result:

ok 1 number(s): "964512417"

Test #7:

score: 5
Accepted
time: 1ms
memory: 3880kb

input:

281 5 1008854383

output:

755282155

result:

ok 1 number(s): "755282155"

Test #8:

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

input:

270 5 1007619367

output:

431828317

result:

ok 1 number(s): "431828317"

Test #9:

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

input:

292 5 1002449813

output:

183613546

result:

ok 1 number(s): "183613546"

Test #10:

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

input:

300 5 1005897091

output:

915308166

result:

ok 1 number(s): "915308166"

Test #11:

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

input:

45 50 1009100993

output:

940158800

result:

ok 1 number(s): "940158800"

Test #12:

score: 5
Accepted
time: 1ms
memory: 3896kb

input:

49 50 1001428049

output:

1045902

result:

ok 1 number(s): "1045902"

Test #13:

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

input:

49 50 1007851073

output:

922264698

result:

ok 1 number(s): "922264698"

Test #14:

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

input:

50 50 1005625571

output:

442192770

result:

ok 1 number(s): "442192770"

Test #15:

score: 5
Accepted
time: 1ms
memory: 3812kb

input:

290 300 1005068699

output:

484359497

result:

ok 1 number(s): "484359497"

Test #16:

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

input:

270 300 1003440637

output:

899894137

result:

ok 1 number(s): "899894137"

Test #17:

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

input:

300 300 1008561979

output:

33407754

result:

ok 1 number(s): "33407754"

Test #18:

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

input:

2991 3000 1004658859

output:

167444547

result:

ok 1 number(s): "167444547"

Test #19:

score: 5
Accepted
time: 1ms
memory: 3812kb

input:

2870 3000 1004054173

output:

860666062

result:

ok 1 number(s): "860666062"

Test #20:

score: 5
Accepted
time: 1ms
memory: 3912kb

input:

3000 3000 1009539589

output:

696222334

result:

ok 1 number(s): "696222334"