QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710261#1984. MentorsbecaidoAC ✓27ms26948kbC++201.0kb2024-11-04 19:14:142024-11-04 19:14:15

Judging History

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

  • [2024-11-04 19:14:15]
  • 评测
  • 测评结果:AC
  • 用时:27ms
  • 内存:26948kb
  • [2024-11-04 19:14:14]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout<<"["<<#HEHE<<"] : ",dout(HEHE)
void dout(){cout<<'\n';}
template<typename T,typename...U>
void dout(T t,U...u){cout<<t<<(sizeof...(u)?", ":""),dout(u...);}
#else
#define debug(...) 7122
#endif

#define int long long
#define ll long long
#define Waimai ios::sync_with_stdio(false),cin.tie(0)
#define FOR(x,a,b) for(int x=a,I=b;x<=I;x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2100;

int n, r, mod;
int dp[SIZE][SIZE];

void solve() {
    cin >> r >> n >> mod;
    dp[1][1] = 1;
    FOR (i, 2, n) {
        FOR (j, 1, i - 1) {
            dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % mod;
            if (i == r) continue;
            dp[i][j] = (dp[i][j] + dp[i - 1][j] * j) % mod;
            dp[i][j - 1] = (dp[i][j - 1] + dp[i - 1][j] * (j * (j - 1) / 2 % mod)) % mod;
        }
    }
    cout << dp[n][1] << '\n';
}

int32_t main() {
    Waimai;
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

1 14 123456789

output:

75904192

result:

ok single line: '75904192'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

7 14 123456789

output:

72179669

result:

ok single line: '72179669'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

13 14 123456789

output:

2702765

result:

ok single line: '2702765'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

14 14 123456789

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

25 50 123456789

output:

65438273

result:

ok single line: '65438273'

Test #6:

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

input:

25 50 123456788

output:

77049037

result:

ok single line: '77049037'

Test #7:

score: 0
Accepted
time: 19ms
memory: 26884kb

input:

1010 2021 999999883

output:

356413310

result:

ok single line: '356413310'

Test #8:

score: 0
Accepted
time: 27ms
memory: 26884kb

input:

1 2021 999999937

output:

141524412

result:

ok single line: '141524412'

Test #9:

score: 0
Accepted
time: 16ms
memory: 26884kb

input:

5 2021 999999929

output:

833185836

result:

ok single line: '833185836'

Test #10:

score: 0
Accepted
time: 19ms
memory: 26948kb

input:

2017 2021 999999797

output:

503659284

result:

ok single line: '503659284'

Test #11:

score: 0
Accepted
time: 21ms
memory: 26944kb

input:

2021 2021 999999751

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 15ms
memory: 17104kb

input:

271 1414 314159265

output:

66534359

result:

ok single line: '66534359'