QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276745#4163. 地精部落SoyTony100 ✓27ms86140kbC++141.3kb2023-12-06 10:15:342023-12-06 10:15:34

Judging History

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

  • [2023-12-06 10:15:34]
  • 评测
  • 测评结果:100
  • 用时:27ms
  • 内存:86140kb
  • [2023-12-06 10:15:34]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int maxn=4e5+10;
const int maxm=1e6+10;
const int mod=1e9+7;
const ull base1=233;
const ull base2=19260817;
const int maxxn=0x7fffffff;
const int minxn=-0x7fffffff;
const db inf=1e13;
const db eps=1e-8;
inline ll read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}
int n,p;
int dp[5005][5005],sum;
int ans;
int main(){
    n=read(),p=read();
    dp[1][1]=1;
    for(int i=2;i<=n;i++){
        sum=0;
        if(i&1){
            dp[i][1]=0;
            for(int j=2;j<=i;j++){
                sum=(sum+dp[i-1][j-1])%p;
                dp[i][j]=sum;
            }
        }
        else{
            dp[i][i]=0;
            for(int j=i-1;j>=1;j--){
                sum=(sum+dp[i-1][j])%p;
                dp[i][j]=sum;
            }
        }
    }
    for(int i=1;i<=n;i++){
        ans=(ans+dp[n][i])%p;
    }
    ans=(ans*2)%p;
    printf("%d\n",ans);
    return 0; 
}

詳細信息

Test #1:

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

input:

9 2811

output:

1817

result:

ok single line: '1817'

Test #2:

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

input:

10 12929

output:

10539

result:

ok single line: '10539'

Test #3:

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

input:

17 21929121

output:

7310012

result:

ok single line: '7310012'

Test #4:

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

input:

18 29121

output:

15047

result:

ok single line: '15047'

Test #5:

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

input:

200 123849291

output:

88055017

result:

ok single line: '88055017'

Test #6:

score: 10
Accepted
time: 3ms
memory: 14240kb

input:

500 182739417

output:

182278339

result:

ok single line: '182278339'

Test #7:

score: 10
Accepted
time: 3ms
memory: 16144kb

input:

550 281321834

output:

25165060

result:

ok single line: '25165060'

Test #8:

score: 10
Accepted
time: 15ms
memory: 53304kb

input:

2500 18239314

output:

16654836

result:

ok single line: '16654836'

Test #9:

score: 10
Accepted
time: 26ms
memory: 81944kb

input:

4000 129394123

output:

59559500

result:

ok single line: '59559500'

Test #10:

score: 10
Accepted
time: 27ms
memory: 86140kb

input:

4200 192340123

output:

81768678

result:

ok single line: '81768678'