QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412094#4163. 地精部落x-camp100 ✓55ms71204kbC++17927b2024-05-16 04:49:272024-05-16 04:49:27

Judging History

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

  • [2024-05-16 04:49:27]
  • 评测
  • 测评结果:100
  • 用时:55ms
  • 内存:71204kb
  • [2024-05-16 04:49:27]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <fstream>
#include <cstring>

using namespace std;

int N, P;
#define NMAX 4203
long long dp[NMAX];
int bi[NMAX][NMAX];

int main() {
 //   freopen("goblin.in","r",stdin);
 //   freopen("goblin.out","w",stdout);
    cin >> N >> P;
    for (int i=0; i<N; i++) {
        bi[i][0] = 1;
        bi[i][i] = 1;
    }
    for (int i=1; i<N; i++) {
        for (int j=1; j<=i; j++) {
            bi[i][j] = (bi[i-1][j-1] + bi[i-1][j]) %P;
        }
    }
    // up pattern first
    dp[2] = 1; dp[1] = 1; dp[0] = 1;
    for (int i=3; i<=N; i++) {
        for (int j=2; j<=i; j += 2 ) {
            long long tmp = dp[j-1]*bi[i-1][j-1] %P;
            tmp = tmp *  dp[i-j] %P;
            dp[i] = (dp[i] + tmp) % P;
        }
    }
    if (N == 1) cout << 1;
    else cout << 2*dp[N] %P;
    return 0;
}




詳細信息

Test #1:

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

input:

9 2811

output:

1817

result:

ok single line: '1817'

Test #2:

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

input:

10 12929

output:

10539

result:

ok single line: '10539'

Test #3:

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

input:

17 21929121

output:

7310012

result:

ok single line: '7310012'

Test #4:

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

input:

18 29121

output:

15047

result:

ok single line: '15047'

Test #5:

score: 10
Accepted
time: 1ms
memory: 7708kb

input:

200 123849291

output:

88055017

result:

ok single line: '88055017'

Test #6:

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

input:

500 182739417

output:

182278339

result:

ok single line: '182278339'

Test #7:

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

input:

550 281321834

output:

25165060

result:

ok single line: '25165060'

Test #8:

score: 10
Accepted
time: 19ms
memory: 44768kb

input:

2500 18239314

output:

16654836

result:

ok single line: '16654836'

Test #9:

score: 10
Accepted
time: 49ms
memory: 69432kb

input:

4000 129394123

output:

59559500

result:

ok single line: '59559500'

Test #10:

score: 10
Accepted
time: 55ms
memory: 71204kb

input:

4200 192340123

output:

81768678

result:

ok single line: '81768678'