結果
問題 | No.2528 pop_(backfront or not) |
ユーザー | otoshigo |
提出日時 | 2023-11-03 21:59:55 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,465 ms / 2,000 ms |
コード長 | 1,439 bytes |
コンパイル時間 | 964 ms |
コンパイル使用メモリ | 87,984 KB |
実行使用メモリ | 91,844 KB |
最終ジャッジ日時 | 2024-09-25 20:16:17 |
合計ジャッジ時間 | 10,859 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<atcoder/modint> using namespace std; using namespace atcoder; using ll=long long; using mint=modint998244353; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} const int MAX=2000010; const ll MOD=998244353; mint fac[MAX+1],finv[MAX+1],inv[MAX+1]; void set_fac(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for (int i=2;i<=MAX;i++){ fac[i]=fac[i-1]*i; inv[i]=-inv[MOD%i]*(MOD/i); finv[i]=finv[i-1]*inv[i]; } } mint cmb(int n,int r){ if (r<0||n<r)return 0; return fac[n]*finv[r]*finv[n-r]; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); set_fac(); int N; cin>>N; N=2*N+1; vector dp(N+1,vector<mint>(N+1)); vector flag(N+1,vector<bool>(N+1)); auto f=[&](auto f,int x,int i)-> mint { if(flag[x][i])return dp[x][i]; if(x==1)return 1; if(i==1||i==x)return 0; flag[x][i]=true; if(i-2>=2)dp[x][i]+=f(f,x-2,i-2)*(i-2)*(i-3)/2; dp[x][i]+=f(f,x-2,i-1)*(1+(ll)(i-2)*(x-i-1)); if(x-i-1>=2)dp[x][i]+=f(f,x-2,i)*(x-i-1)*(x-i-2)/2; return dp[x][i]; }; for(int i=1;i<=N;i++)cout<<f(f,N,i).val()<<"\n"; }