# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
992601 |
2024-06-04T19:09:48 Z |
Abito |
NoM (RMI21_nom) |
C++17 |
|
1 ms |
2556 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==b+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;
int x=2*n;
for (int i=1;i && x;i++){
b=i;
a[i]=min(x,2*n/m);
x-=a[i];
}
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 |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2556 KB |
Output is correct |
8 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2556 KB |
Output is correct |
8 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2556 KB |
Output is correct |
8 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2556 KB |
Output is correct |
8 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2556 KB |
Output is correct |
8 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |