# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
992605 |
2024-06-04T19:14:34 Z |
Abito |
NoM (RMI21_nom) |
C++17 |
|
239 ms |
51796 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=5005,M=1e9+7;
int dp[N][N],n,m,a[N],b,fac[N],p2[N],inv[N];
bool vis[N][N];
int C(int n,int k){
if (n<0 || k<0 || n-k<0) return 0;
return fac[n]*inv[k]%M*inv[n-k]%M;
}
int pow(int x,int y){
if (!y) return 1;
int z=pow(x,y/2);
z=z*z%M;
if (y&1) z=z*x%M;
return z;
}
int rec(int i,int j){
if (i==m+1) return (j==0);
if (vis[i][j]) return dp[i][j];
vis[i][j]=1;
for (int k=0;k<=min(a[i]/2,j);k++){
dp[i][j]=(dp[i][j]+rec(i+1,j-k)*C(j,k)%M*C(a[i],2*k)%M*fac[2*k]%M)%M;
}return dp[i][j];
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
fac[0]=1;p2[0]=1;
for (int i=1;i<N;i++) p2[i]=p2[i-1]*2LL%M;
for (int i=1;i<N;i++) fac[i]=fac[i-1]*i%M;
inv[N-1]=pow(fac[N-1],M-2);
for (int i=N-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%M;
cin>>n>>m;
for (int i=1;i<=2*n;i++) if (i%m)a[i%m]++; else a[m]++;
//for (int j=1;j<=20;j++) cout<<a[j]<<' ';cout<<endl;
int ans=fac[2*n];
for (int i=1;i<=n;i++){
//cout<<rec(1,i)<<endl;
if (i&1) ans=(ans-rec(1,i)*C(n,i)%M*fac[2*n-2*i]%M+M)%M;
else ans=(ans+rec(1,i)*C(n,i)%M*fac[2*n-2*i]%M)%M;
}cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
4 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
2652 KB |
Output is correct |
24 |
Correct |
5 ms |
3796 KB |
Output is correct |
25 |
Correct |
4 ms |
4936 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
6 ms |
5724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
4 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
2652 KB |
Output is correct |
24 |
Correct |
5 ms |
3796 KB |
Output is correct |
25 |
Correct |
4 ms |
4936 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
6 ms |
5724 KB |
Output is correct |
28 |
Correct |
8 ms |
2652 KB |
Output is correct |
29 |
Correct |
15 ms |
6896 KB |
Output is correct |
30 |
Correct |
20 ms |
10468 KB |
Output is correct |
31 |
Correct |
8 ms |
2652 KB |
Output is correct |
32 |
Correct |
18 ms |
7144 KB |
Output is correct |
33 |
Correct |
26 ms |
11600 KB |
Output is correct |
34 |
Correct |
57 ms |
16724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
4 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
2652 KB |
Output is correct |
24 |
Correct |
5 ms |
3796 KB |
Output is correct |
25 |
Correct |
4 ms |
4936 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
6 ms |
5724 KB |
Output is correct |
28 |
Correct |
8 ms |
2652 KB |
Output is correct |
29 |
Correct |
15 ms |
6896 KB |
Output is correct |
30 |
Correct |
20 ms |
10468 KB |
Output is correct |
31 |
Correct |
8 ms |
2652 KB |
Output is correct |
32 |
Correct |
18 ms |
7144 KB |
Output is correct |
33 |
Correct |
26 ms |
11600 KB |
Output is correct |
34 |
Correct |
57 ms |
16724 KB |
Output is correct |
35 |
Correct |
46 ms |
2708 KB |
Output is correct |
36 |
Correct |
183 ms |
41160 KB |
Output is correct |
37 |
Correct |
45 ms |
2652 KB |
Output is correct |
38 |
Correct |
96 ms |
20304 KB |
Output is correct |
39 |
Correct |
140 ms |
34468 KB |
Output is correct |
40 |
Correct |
239 ms |
51796 KB |
Output is correct |