# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871082 |
2023-11-09T20:48:18 Z |
Ahmed57 |
NoM (RMI21_nom) |
C++17 |
|
16 ms |
2584 KB |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long fact[10001],inv[10001];
long long fast(long long a,long long b){
if(b==0)return 1;
if(b==1)return a;
long long h = fast(a,b/2);
h*=h;h%=mod;
if(b%2)return (h*a)%mod;
else return h;
}
long long nPr(long long a,long long b){
return (fact[a]*inv[a-b])%mod;
}
long long nCr(long long a,long long b){
return (((fact[a]*inv[a-b])%mod)*inv[b])%mod;
}
long long dp[501][501];
int n,m;int cnt[501];
long long solve(int i,int rem){
if(i==m){
return fact[rem*2];
}
if(dp[i][rem]!=-1)return dp[i][rem];
long long de = 1;
long long all =0;
for(int j = 0;j<=cnt[i]/2;j++){
all+=(((((solve(i+1,rem-j)*nPr(cnt[i],j*2))%mod)*nCr(rem,j))%mod)*de)%mod;
all%=mod;
de*=(mod-1);de%=mod;
}
return dp[i][rem] = all;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
memset(dp,-1,sizeof dp);
fact[0] = 1;inv[0] = fast(fact[0],mod-2);
for(long long i = 1;i<=1e4;i++){
fact[i]=(fact[i-1]*i)%mod;
inv[i]=fast(fact[i],mod-2);
}
cin>>n>>m;
for(int i = 0;i<2*n;i++){
cnt[i%m]++;
}
cout<<solve(0,n)<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2584 KB |
Output is correct |
6 |
Correct |
5 ms |
2556 KB |
Output is correct |
7 |
Correct |
5 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2396 KB |
Output is correct |
9 |
Correct |
5 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2584 KB |
Output is correct |
6 |
Correct |
5 ms |
2556 KB |
Output is correct |
7 |
Correct |
5 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2396 KB |
Output is correct |
9 |
Correct |
5 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
2456 KB |
Output is correct |
13 |
Correct |
5 ms |
2392 KB |
Output is correct |
14 |
Correct |
5 ms |
2576 KB |
Output is correct |
15 |
Correct |
5 ms |
2396 KB |
Output is correct |
16 |
Correct |
5 ms |
2392 KB |
Output is correct |
17 |
Correct |
5 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
5 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2584 KB |
Output is correct |
6 |
Correct |
5 ms |
2556 KB |
Output is correct |
7 |
Correct |
5 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2396 KB |
Output is correct |
9 |
Correct |
5 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
2456 KB |
Output is correct |
13 |
Correct |
5 ms |
2392 KB |
Output is correct |
14 |
Correct |
5 ms |
2576 KB |
Output is correct |
15 |
Correct |
5 ms |
2396 KB |
Output is correct |
16 |
Correct |
5 ms |
2392 KB |
Output is correct |
17 |
Correct |
5 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
5 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2396 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
8 ms |
2396 KB |
Output is correct |
23 |
Correct |
6 ms |
2396 KB |
Output is correct |
24 |
Correct |
7 ms |
2396 KB |
Output is correct |
25 |
Correct |
8 ms |
2576 KB |
Output is correct |
26 |
Correct |
7 ms |
2396 KB |
Output is correct |
27 |
Correct |
9 ms |
2568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2584 KB |
Output is correct |
6 |
Correct |
5 ms |
2556 KB |
Output is correct |
7 |
Correct |
5 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2396 KB |
Output is correct |
9 |
Correct |
5 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
2456 KB |
Output is correct |
13 |
Correct |
5 ms |
2392 KB |
Output is correct |
14 |
Correct |
5 ms |
2576 KB |
Output is correct |
15 |
Correct |
5 ms |
2396 KB |
Output is correct |
16 |
Correct |
5 ms |
2392 KB |
Output is correct |
17 |
Correct |
5 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
5 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2396 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
8 ms |
2396 KB |
Output is correct |
23 |
Correct |
6 ms |
2396 KB |
Output is correct |
24 |
Correct |
7 ms |
2396 KB |
Output is correct |
25 |
Correct |
8 ms |
2576 KB |
Output is correct |
26 |
Correct |
7 ms |
2396 KB |
Output is correct |
27 |
Correct |
9 ms |
2568 KB |
Output is correct |
28 |
Incorrect |
16 ms |
2396 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2584 KB |
Output is correct |
6 |
Correct |
5 ms |
2556 KB |
Output is correct |
7 |
Correct |
5 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2396 KB |
Output is correct |
9 |
Correct |
5 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
2456 KB |
Output is correct |
13 |
Correct |
5 ms |
2392 KB |
Output is correct |
14 |
Correct |
5 ms |
2576 KB |
Output is correct |
15 |
Correct |
5 ms |
2396 KB |
Output is correct |
16 |
Correct |
5 ms |
2392 KB |
Output is correct |
17 |
Correct |
5 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
5 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2396 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
8 ms |
2396 KB |
Output is correct |
23 |
Correct |
6 ms |
2396 KB |
Output is correct |
24 |
Correct |
7 ms |
2396 KB |
Output is correct |
25 |
Correct |
8 ms |
2576 KB |
Output is correct |
26 |
Correct |
7 ms |
2396 KB |
Output is correct |
27 |
Correct |
9 ms |
2568 KB |
Output is correct |
28 |
Incorrect |
16 ms |
2396 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |