結果
問題 |
No.2904 Distinct Multisets in a Way
|
ユーザー |
|
提出日時 | 2025-07-04 03:21:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 982 bytes |
コンパイル時間 | 1,612 ms |
コンパイル使用メモリ | 194,864 KB |
実行使用メモリ | 9,564 KB |
最終ジャッジ日時 | 2025-07-04 03:21:10 |
合計ジャッジ時間 | 3,463 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; using pii=pair<int,int>; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) const int N=500005,mod=998244353; int add(int x, int y){x+=y; if(x>=mod) x-=mod; return x;} int sub(int x, int y){x-=y; if(x<0) x+=mod; return x;} int mul(int x, int y){return ((ll)x)*y%mod;} int n,fac[N],inv[N],ifac[N]; void amano_hina_is_the_goat(){ fac[0]=inv[1]=ifac[0]=1; for(int i=1; i<N; ++i) fac[i]=mul(fac[i-1],i); for(int i=2; i<N; ++i) inv[i]=mul(inv[mod%i],mod-mod/i); for(int i=1; i<N; ++i) ifac[i]=mul(ifac[i-1],inv[i]); cin >> n; int res=0; for(int i=0; i*2<=n; ++i) res=add(res,mul(mul(fac[n],ifac[n-i*2]),mul(ifac[i],ifac[i]))); res=mul(sub(res,1),(mod+1)/2); cout << res << "\n"; } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); cout << fixed << setprecision(20); int t=1; //cin >> t; while(t--) amano_hina_is_the_goat(); }