#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(int x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,MOD;
int dp[305][605]; //m-1
int dp2[305][605]; //m
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>MOD;
dp[1][2]=1;
rep(x,2,n+1){
rep(y,0,605) if (dp[x-1][y]){
dp[x][2]=(dp[x][2]+dp[x-1][y])%MOD;
dp[x][y+1]=(dp[x][y+1]+dp[x-1][y]*(2*(x-1)-y))%MOD;
dp2[x][1]=(dp2[x][1]+dp[x-1][y]*y)%MOD;
}
rep(y,0,605) if (dp2[x-1][y]){
dp[x][2+y]=(dp[x][2+y]+dp2[x-1][y])%MOD;
dp2[x][y+1]=(dp2[x][y+1]+dp2[x-1][y]*(2*(x-1)-y))%MOD;
}
}
int ans=0;
rep(y,0,605) ans=(ans+dp[n][y]+dp2[n][y])%MOD;
// cout<<ans<<endl;
int tot=1;
rep(x,1,n+1) tot=tot*(2*x-1)%MOD;
cout<<(tot-ans+MOD)%MOD<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |