QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#311835 | #8015. 鸡 | schrodingerstom | 100 ✓ | 152ms | 3940kb | C++14 | 2.1kb | 2024-01-22 20:57:50 | 2024-01-22 20:57:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool memBeg;
constexpr int maxn=3005;
constexpr int inf=0x3f3f3f3f;
int n,m,mod,a[maxn],f[maxn];
bool memEn;
void fl() {
freopen("chicken.in","r",stdin);
freopen("chicken.out","w",stdout);
}
int main() {
fprintf(stderr,"%.24lf\n",fabs(&memEn-&memBeg)/1024.0/1024.0);
// fl();
scanf("%d%d%d",&n,&m,&mod);
f[0]=1; f[1]=m+1;
for(int i=2;i<=n;i++) {
f[i]=(f[i-1]+1ll*m*f[i-2])%mod;
}
int ret=f[n];
// printf("line = %d, ret = %d\n",__LINE__,ret);
for(int i=1;i<=n;i++) {
for(int j=i;j<=n;j++) {
if(i==2||n-j==1) continue;
int coef=1;
if(i>=4) coef=1ll*coef*f[i-4]%mod*m%mod;
else if(i==3) coef=1ll*coef*m%mod;
if(n-j>=3) coef=1ll*coef*f[n-j-3]%mod*m%mod;
else if(n-j==2) coef=1ll*coef*m%mod;
// printf("i = %d, j = %d, coef = %d\n",i,j,coef);
ret=(ret+1ll*coef*((j-i+1)/2)%mod*m)%mod;
}
}
// printf("line = %d, ret = %d\n",__LINE__,ret);
for(int i=1;i<=n;i++) {
int coef=1;
if(i>=2) coef=1ll*coef*f[i-2]%mod;
if(n-i>=1) coef=1ll*coef*f[n-i-1]%mod;
for(int x=1;x<m;x++) ret=(ret+1ll*(m-x)*coef)%mod;
}
int sum3=0,sum2=0,sum1=0;
for(int x=1;x<m;x++) {
sum1+=m-x; sum1-=(sum1>=mod)*mod;
sum2=(sum2+1ll*(m-x)*(m-x))%mod;
sum3=(sum3+1ll*(m-x)*(m-x)%mod*(m-x))%mod;
}
for(int i=1;i<=n;i++) {
for(int j=i;j<=n;j++) {
if(i==2||n-j==1||((j-i)&1)) continue;
int coef=1,cnt=3;
if(i>=4) coef=1ll*coef*f[i-4]%mod;
else if(i==3) coef=1ll*coef;
else cnt--;
if(n-j>=3) coef=1ll*coef*f[n-j-3]%mod;
else if(n-j==2) coef=1ll*coef;
else cnt--;
if(cnt==3) ret-=1ll*coef*sum3%mod;
else if(cnt==2) ret-=1ll*coef*sum2%mod;
else ret-=1ll*coef*sum1%mod;
if(ret<0) ret+=mod;
}
}
printf("%d\n",ret);
return 0;
}
詳細信息
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: 1ms
memory: 3936kb
input:
5 4 1002682123
output:
649
result:
ok 1 number(s): "649"
Test #3:
score: 5
Accepted
time: 1ms
memory: 3868kb
input:
287 1 1003060133
output:
328406329
result:
ok 1 number(s): "328406329"
Test #4:
score: 5
Accepted
time: 1ms
memory: 3852kb
input:
279 1 1004432189
output:
222258837
result:
ok 1 number(s): "222258837"
Test #5:
score: 5
Accepted
time: 1ms
memory: 3940kb
input:
300 1 1005912203
output:
707086810
result:
ok 1 number(s): "707086810"
Test #6:
score: 5
Accepted
time: 0ms
memory: 3868kb
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: 2ms
memory: 3940kb
input:
270 5 1007619367
output:
431828317
result:
ok 1 number(s): "431828317"
Test #9:
score: 5
Accepted
time: 0ms
memory: 3880kb
input:
292 5 1002449813
output:
183613546
result:
ok 1 number(s): "183613546"
Test #10:
score: 5
Accepted
time: 1ms
memory: 3884kb
input:
300 5 1005897091
output:
915308166
result:
ok 1 number(s): "915308166"
Test #11:
score: 5
Accepted
time: 0ms
memory: 3880kb
input:
45 50 1009100993
output:
940158800
result:
ok 1 number(s): "940158800"
Test #12:
score: 5
Accepted
time: 0ms
memory: 3904kb
input:
49 50 1001428049
output:
1045902
result:
ok 1 number(s): "1045902"
Test #13:
score: 5
Accepted
time: 1ms
memory: 3880kb
input:
49 50 1007851073
output:
922264698
result:
ok 1 number(s): "922264698"
Test #14:
score: 5
Accepted
time: 1ms
memory: 3888kb
input:
50 50 1005625571
output:
442192770
result:
ok 1 number(s): "442192770"
Test #15:
score: 5
Accepted
time: 2ms
memory: 3940kb
input:
290 300 1005068699
output:
484359497
result:
ok 1 number(s): "484359497"
Test #16:
score: 5
Accepted
time: 2ms
memory: 3868kb
input:
270 300 1003440637
output:
899894137
result:
ok 1 number(s): "899894137"
Test #17:
score: 5
Accepted
time: 2ms
memory: 3876kb
input:
300 300 1008561979
output:
33407754
result:
ok 1 number(s): "33407754"
Test #18:
score: 5
Accepted
time: 152ms
memory: 3892kb
input:
2991 3000 1004658859
output:
167444547
result:
ok 1 number(s): "167444547"
Test #19:
score: 5
Accepted
time: 137ms
memory: 3872kb
input:
2870 3000 1004054173
output:
860666062
result:
ok 1 number(s): "860666062"
Test #20:
score: 5
Accepted
time: 152ms
memory: 3876kb
input:
3000 3000 1009539589
output:
696222334
result:
ok 1 number(s): "696222334"