結果
問題 | No.2530 Yellow Cards |
ユーザー |
|
提出日時 | 2023-11-03 22:01:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 228 ms / 2,000 ms |
コード長 | 816 bytes |
コンパイル時間 | 1,753 ms |
コンパイル使用メモリ | 166,984 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-25 20:20:42 |
合計ジャッジ時間 | 4,808 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long longconst int p=998244353;int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}int inv(int x) {return po(x,p-2);}const int maxn=5e3+5;int ways[maxn];int ways2[maxn];int res;int32_t main(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,k;cin>>n>>k;ways[0]=1;int in=inv(n);res=n;for(int i=0;i<k;++i){fill(ways2,ways2+maxn,0);for(int j=0;j<=n;++j){ways2[j+1]+=(((n-j)*in)%p)*ways[j];ways2[j+1]%=p;if(j) {int h=(((j*in)%p)*ways[j])%p;ways2[j-1]+=h;ways2[j-1]%=p;res+=h;res%=p;}}copy(ways2,ways2+maxn,ways);}cout<<(res%p+p)%p;return 0;}