QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#308253 | #8015. 鸡 | 275307894a | 100 ✓ | 46ms | 4044kb | C++14 | 1.5kb | 2024-01-19 19:52:02 | 2024-01-19 19:52:02 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=3e3+5,M=200+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,p;
ll f[N];
void Solve(){
int i,j;scanf("%d%d%d",&n,&m,&p);
f[0]=1;f[1]=m+1;
for(i=2;i<=n;i++) f[i]=(f[i-1]+f[i-2]*m)%p;
ll ans=f[n];
for(i=1;i<=n;i++){
for(j=i+1;j<=n;j++){
ans+=(j-i+1)/2*m*(i^2?f[max(i-4,0)]*(i^1?m:1)%p:0)%p*(j^n-1?f[max(n-j-3,0)]*(j^n?m:1)%p:0)%p;
}
}
for(i=1;i<=n;i++) ans+=(m-1)*m/2*f[max(i-2,0)]%p*f[max(n-i-1,0)]%p;
ll w=0;for(i=1;i<=m;i++) w+=1ll*(m-i)*(m-i)%p*(m-i)%p;w%=p;
cerr<<ans<<'\n';
for(i=1;i<=n;i++){
for(j=i+4;j<=n;j+=2) ans-=w*f[max(i-2,0)]%p*f[max(n-j-1,0)]%p;
}
cerr<<ans<<'\n';
w=0;for(i=1;i<=m;i++) w+=1ll*(m-i)*(m-i);w%=p;
for(i=3;i<=n;i+=2) ans-=w*f[max(n-i-1,0)]%p;
for(i=n-2;i>=1;i-=2) ans-=w*f[max(i-2,0)]%p;
w=0;for(i=1;i<=m;i++) w+=m-i;w%=p;
if(n&1) ans-=w;
printf("%lld\n",(ans%p+p)%p);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 5
Accepted
time: 1ms
memory: 3988kb
input:
5 5 1004326439
output:
1281
result:
ok 1 number(s): "1281"
Test #2:
score: 5
Accepted
time: 1ms
memory: 3968kb
input:
5 4 1002682123
output:
649
result:
ok 1 number(s): "649"
Test #3:
score: 5
Accepted
time: 1ms
memory: 4004kb
input:
287 1 1003060133
output:
328406329
result:
ok 1 number(s): "328406329"
Test #4:
score: 5
Accepted
time: 1ms
memory: 3972kb
input:
279 1 1004432189
output:
222258837
result:
ok 1 number(s): "222258837"
Test #5:
score: 5
Accepted
time: 1ms
memory: 3856kb
input:
300 1 1005912203
output:
707086810
result:
ok 1 number(s): "707086810"
Test #6:
score: 5
Accepted
time: 1ms
memory: 4004kb
input:
288 5 1003307827
output:
964512417
result:
ok 1 number(s): "964512417"
Test #7:
score: 5
Accepted
time: 1ms
memory: 3988kb
input:
281 5 1008854383
output:
755282155
result:
ok 1 number(s): "755282155"
Test #8:
score: 5
Accepted
time: 1ms
memory: 3988kb
input:
270 5 1007619367
output:
431828317
result:
ok 1 number(s): "431828317"
Test #9:
score: 5
Accepted
time: 1ms
memory: 3860kb
input:
292 5 1002449813
output:
183613546
result:
ok 1 number(s): "183613546"
Test #10:
score: 5
Accepted
time: 1ms
memory: 3916kb
input:
300 5 1005897091
output:
915308166
result:
ok 1 number(s): "915308166"
Test #11:
score: 5
Accepted
time: 0ms
memory: 3984kb
input:
45 50 1009100993
output:
940158800
result:
ok 1 number(s): "940158800"
Test #12:
score: 5
Accepted
time: 0ms
memory: 3944kb
input:
49 50 1001428049
output:
1045902
result:
ok 1 number(s): "1045902"
Test #13:
score: 5
Accepted
time: 0ms
memory: 3976kb
input:
49 50 1007851073
output:
922264698
result:
ok 1 number(s): "922264698"
Test #14:
score: 5
Accepted
time: 1ms
memory: 3916kb
input:
50 50 1005625571
output:
442192770
result:
ok 1 number(s): "442192770"
Test #15:
score: 5
Accepted
time: 1ms
memory: 3968kb
input:
290 300 1005068699
output:
484359497
result:
ok 1 number(s): "484359497"
Test #16:
score: 5
Accepted
time: 1ms
memory: 4004kb
input:
270 300 1003440637
output:
899894137
result:
ok 1 number(s): "899894137"
Test #17:
score: 5
Accepted
time: 1ms
memory: 4008kb
input:
300 300 1008561979
output:
33407754
result:
ok 1 number(s): "33407754"
Test #18:
score: 5
Accepted
time: 46ms
memory: 4020kb
input:
2991 3000 1004658859
output:
167444547
result:
ok 1 number(s): "167444547"
Test #19:
score: 5
Accepted
time: 38ms
memory: 4044kb
input:
2870 3000 1004054173
output:
860666062
result:
ok 1 number(s): "860666062"
Test #20:
score: 5
Accepted
time: 46ms
memory: 4016kb
input:
3000 3000 1009539589
output:
696222334
result:
ok 1 number(s): "696222334"