結果
問題 | No.2381 Gift Exchange Party |
ユーザー | Nzt3 |
提出日時 | 2023-07-14 22:08:04 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 708 bytes |
コンパイル時間 | 2,065 ms |
コンパイル使用メモリ | 200,652 KB |
実行使用メモリ | 8,284 KB |
最終ジャッジ日時 | 2024-09-16 07:11:04 |
合計ジャッジ時間 | 3,259 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr int mod=998244353; ll fac[200005]; ll inv[200005]; ll invf[200005]; ll modcomb(int n,int r){ if(n<r)return 0ll; return fac[n]*invf[r]%mod*invf[n-r]%mod; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); fac[0]=inv[0]=invf[0]=1; fac[1]=inv[1]=invf[1]=1; for(int i=2;i<200005;i++){ fac[i]=fac[i-1]*i%mod; inv[i]=inv[mod%i]*(mod-mod/i)%mod; invf[i]=invf[i-1]*inv[i]%mod; } int N,P; cin>>N>>P; ll ans=fac[N]; ll t=1; for(int i=0;i<=N/P;i++){ ans=(ans-t*invf[i])%mod; if(P<=N)t=t*fac[P-1]%mod; if(P<=N)t=t*modcomb(N-P*i,P)%mod; } if(ans<0)ans+=mod; cout<<ans<<'\n'; }