#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
const ll MOD=1000000007LL;
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);}
int main(){
ll n,k;cin>>n>>k;if(n>3000)return 0;
vector<vector<ll>> dp(n+10,vector<ll>(n+10));
dp[0][0]=1;
for(ll i=1;i<=n;i++){
for(ll j=0;j<i;j++){//i+1通り挿入できる
dp[i][j]+=dp[i-1][j]*(j+1LL)%MOD;
if(j>0){
dp[i][j]+=dp[i-1][j-1]*(i-j)%MOD;
}
dp[i][j]%=MOD;
}
}
cout<<dp[n][k-1]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
432 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
432 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1024 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1024 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
896 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
432 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1024 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1024 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
896 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
13 ms |
8292 KB |
Output is correct |
22 |
Correct |
15 ms |
8448 KB |
Output is correct |
23 |
Correct |
12 ms |
8320 KB |
Output is correct |
24 |
Correct |
11 ms |
8320 KB |
Output is correct |
25 |
Correct |
11 ms |
8448 KB |
Output is correct |
26 |
Correct |
14 ms |
8320 KB |
Output is correct |
27 |
Correct |
12 ms |
8364 KB |
Output is correct |
28 |
Correct |
6 ms |
3328 KB |
Output is correct |
29 |
Correct |
2 ms |
612 KB |
Output is correct |
30 |
Correct |
12 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
432 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1024 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1024 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
896 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
13 ms |
8292 KB |
Output is correct |
22 |
Correct |
15 ms |
8448 KB |
Output is correct |
23 |
Correct |
12 ms |
8320 KB |
Output is correct |
24 |
Correct |
11 ms |
8320 KB |
Output is correct |
25 |
Correct |
11 ms |
8448 KB |
Output is correct |
26 |
Correct |
14 ms |
8320 KB |
Output is correct |
27 |
Correct |
12 ms |
8364 KB |
Output is correct |
28 |
Correct |
6 ms |
3328 KB |
Output is correct |
29 |
Correct |
2 ms |
612 KB |
Output is correct |
30 |
Correct |
12 ms |
8192 KB |
Output is correct |
31 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |